I am trying a simple Computer Vision program with OpenCV. After creating the Python file, I run it through Jupyter Lab directly on the Terminal to avoid bugs. However, it opens a python3 file (not an image) and I cannot see the image.
I have tried the following:
Step 1: Terminal
Step 2: File not responding
Do you have any clue why this is happening?
Related
I have a program that prints the rgba of all the pixels in an image using PIL. The problem is that when I run the program in VSCode, it prints a second or so of output, and then freezes. My whole computer then freezes, and I have to power it off and restart it.
However, when I run the program in the GNOME terminal, it completes successfully. Could anyone tell me why VSCode does this, and if there is a way to prevent it? (in other words, what is the difference between the GNOME terminal and the VSCode terminal?)
The code:
import PIL
from PIL import Image
image = Image.open("/home/user/i.jpg")
for i in image.getdata():
print(i, end="")
Here is the image I am using:
This problem is not specific to the image code, this code is just a good way to demonstrate the kind of code that causes this error. I'm using Python 3.8.10 in VSCode 1.52.1 on an Ubuntu 20.04.2.
It looks like just because the picture which you are using is too large that caused too many outputs, I have tried some litter images and it works well.
Update:
The terminal was integrated into the VSCode. It has been customed, so it has different strategies such as memory strategy.
And looks like we should avoid outputs too much data in the integrated terminal in the VSCode. Some people have run across the same issue.
And it looks like increasing the size of the terminal panel is helpful to outputs the data more smoothly.
So I'm playing with python3 on Cloud9, got interested in trying pygame and found a recommendation to install cloud9-vnc for a desktop display. Got both of those things to work, but not in tandem. I'm a rather newbish with Linux and VNC, so I'm stuck at the moment. Any chance I can get pygame output on a VNC desktop?
What I have so far is that I've installed pygame using this and cloud9-vnc using this. Pygame import and commands run smoothly (both in terminal and script) and when I run the script with c9vnc I get the link to a VNC desktop. However, the desktop is clear, apart from Ubuntu logo.
The program doesn't actually seems to be running, considering that it doesn't display the text to be printed
In fact, it seems that it's not even started to run.
However, inside the VNC desktop I have the access to complete cloud9 workspace, including installed pygame, which does work, albeit a bit more clunky, compared to cloud9's interface.
So what I want to ask is is there a way for me to write and run a code on cloud9's default interface that would directly display the output in VNC's desktop, with little to no additional interaction?
I have a hangman style program that calls on Pillows to display images, but instead it just opens a python process as depicted in the images while displaying nothing:
I've installed Pillows successfully, and running the program on a Windows PC with WinPy opens the image.
I set up PyCharm for remote debugging according to this tutorial on CodeProject
http://www.codeproject.com/Tips/987276/Remote-Programming-of-RaspberryPi-using-PyCharm
I am now wondering if it is possible to execute a Python Script with the help of PyCharm on the RaspberryPI and receive the output in PyCharm. Specifically I want to do some image processing and display the image with the help of OpenCV. It would be great to get the image displayed on my Windows machine, not on the Pi.
Another usecase, I want to create some matplot figure, execute the script on the pi and show the Output back in PyCharm on my Windows machine.
Is this possiple?
Kind Regards
You can do this using OpenCV Image Viewer Plugin. Debug you program using remote interpreter in Pycharm, stop at the breakpoint and choose "View as image".
https://plugins.jetbrains.com/plugin/14371-opencv-image-viewer
Disclaimer: I'm an author of this plugin
I am using wand library in my raspberry project running raspbian and python 2.7.
I have a code part as below to display picture from an url:
with Image(file=urllib2.urlopen(r.text)) as imageOBJ:
display(imageOBJ)
These lines display the image correctly. However, I want this window to stay open and my process to continue with other things in my script. Because after 30 seconds I want to repeat the same thing and change the image in the window. Right now, my code is not running until I close the display window.
Please note that this is not the case on my mac but only on raspberry pi B+ , wheezy raspbian.
How can I prevent this behaviour without closing the image display window?
Thanks in advance
This behavior is expected as both Windows & OS X call the OS's run command start & open respectively -- see reference. On the Raspberry Pi, and other like systems, the wand library calls MagickDisplayImage directly on Python's MainThread.
To emulate like behavior on the Raspberry Pi use the xdg-open utility, and Python's subprocess and tmpfile modules.
Create a temporary file to hold the image
Write image to temporary file
Call xdg-open to open temporary file in an isolated process.
import subprocess, tempfile
from wand.image import Image
with Image(filename='wizard:') as imageOBJ:
tempOBJ = tempfile.NamedTemporaryFile(suffix='.jpg',
prefix='/tmp/myProject-',
delete=False)
imageOBJ.save(file=tempOBJ)
subprocess.call('xdg-open {}'.format(tempOBJ.name), shell=True)
Of course mileage will vary across OS distro/version/desktop-environment.