How can I make SimpleCV show image? - python

I am using the following code from Simple CV tutorial
logo = Image("simplecv")
logo.show()
But then it shows up a small window but blank, without image.
Could you help me?
Thank you

just add a simple line in your code and it will work if you are running this code with a script file, otherwise just save an image on your desktop and provide the path of that image to your code "Image("path")" if still you are gating the same error please install it again.
logo = Image("simplecv")
logo.show()
raw_input("Press Enter for EXIT")

This link helped me: Image.show() won't display the picture
For linux users: if you installed simpleCV from Software Center, then check if you have sampleimages folder in
/usr/lib/pymodules/python2.7/SimpleCV/
If it's not there, obtain it from
https://github.com/sightmachine/SimpleCV#ubuntu-1204

Related

pyautogui.locateOnScreen() Returns... Nothing?

I'm trying to use PyAutoGui's image recognition functions. (OS X)
Needless to say, I'm running into some slight issues that I can't seem to solve myself no matter where I look or what I do. I'm attempting to have PyAutoGui click on the Chrome shortcut based off a .png screenshot saved to my desktop.
Here's my code in terminal:
>>>import pyautogui
>>>chrome = pyautogui.locateOnScreen('/Users/ianscalzo/Desktop/chrome.png")
>>>
I get no backfire on my filepath, but it causes my shell/terminal to return nothing but go to a new line. (As shown in the code example above - Just causes terminal to go to a blank ">>>")
I don't really understand why it doesn't do anything but go to a new line, so any insight would be greatly appreciated.
Thank you so much!
After struggling with this forever also, finally figured out that you either use command line to take the screenshot or using the screenshot button with windows key. It doesn't work with the snipping tool.
so try:
image = pyautogui.screenshot()
image.save('testing.png')
Go and crop testing.png as small as possible so that locateOnScreen works faster. Then go back to the terminal and type:
pyautogui.locateOnScreen('testing.png')

PIL image display error "It looks like the image was moved or renamed"

Here is a bit of my code:
from PIL import Image
image = Image.open('fall-foliage-1740841_640.jpg')
image.show()
The error is when the default photo viewer is started and shows the error
"It looks like the image was moved or renamed"
Restarting doesn't help. I am just starting using PIL and can't find a way round this.
I appreciate any help. Thanks!!!
You can just add a prompt to keep the python script from closing.
from PIL import Image
image = Image.open('fall-foliage-1740841_640.jpg')
image.show()
input()
Essentially, The problem is that when the image is opened, it's stored in temporary memory. So when the program closes, the image is not saved and is lost from memory. There for when the Photos app or whatever app you are using to view the image, searches for the image, it's already gone when the script is finished executing.
Hope this helps

Python image recognition with pyautogui

When I try to recognize an image with pyautogui it just says: None
import pyautogui
s = pyautogui.locateOnScreen('Dark.png')
print s
When I ran this code the picture was on my screen but it still failed.
Pyautogui.locateOnScreen has a parameter that specifies the 'confidence' you have in the image you enter.
This way, pyautogui will deal with slight pixel deviations.
For example:
import pyautogui
s = pyautogui.locateOnScreen('Dark.png', confidence=0.9)
print(s)
For more information, see https://buildmedia.readthedocs.org/media/pdf/pyautogui/latest/pyautogui.pdf.
It's pixel perfect.
It can't find the image if it is not 100% match.
For example, I cropped an area with an Opera extension. Then I ran my script with Firefox, and pyautogui did not recognize it.
Don't let your image get resized or compressed by screen capture software or extensions.
Use the same window/screen (size, resolution) as where you saved your screenshot.
On my system, I get this if the picture is on a second monitor. If I move it to the main screen, the image is located successfully.
It looks like multiple-monitor functionality is not yet implemented:
From http://pyautogui.readthedocs.org/en/latest/roadmap.html
Future features planned (specific versions not planned yet):
Find a list of all windows and their captions.
Click coordinates relative to a window, instead of the entire screen.
Make it easier to work on systems with multiple monitors.
...

How to use Pillow to display an image?

Edit:
It might help to know that I'm using python 2.7.9 (that's what was taught in my GIS class).
I've almost got it working I think. Although now it's a new question.
I have this code
from PIL import Image
im = Image.open("C:/users/Chrostopher/Asuna.png")
There are no error messages and my screen flashed black like it wanted to do something, but the picture didn't show/open/display. What should I do?
Thanks for all the help so far. I feel like I'm slowly (and with many mistakes) learning something useful.
Old:
I am very, very new at this, which is why I'm asking. I've looked around for help, but there's always one thing I don't understand and it's just turned into a very deep rabbit hole.
When I've tried the code I've seen here, it doesn't work. Looking further, I need the Python Image Library (PIL). I've downloaded it, but I can't figure out how to set it up to work in Python. The file is a .gz. Is there some place I need to put the file or some way to import it?
If you could answer step by step, that would be wonderful for this extreme newb.
This is the code I have (to try and open an image which is the end goal)
import Image
def main():
filename = "desert.jpg"
image = Image.open(filename)
image.show
del image
if (__name__ == "__main__"):
main()
Is there something I'm missing or not doing right that is messing up what I'm trying to do?
First install Pillow with "pip"
$ pip install Pillow
Then, instead writing
import Image
In the first line, you can use:
from PIL import Image

Display an image with Python on Linux Angstrom

I have a Python script that displays images fullscreen on a BeagleBoard with the GUI disabled. The script is started when the board boots. For this I use PyGame which works perfectly fine. Except for some reason the image qwality is scaled down. Because the images are stored in HQ I assume that PyGame resamples the image. I was unable to find out where this can be changed so I decided to replace PyGame, it also seems a bit much to "just" display an image.
I have the code below to display the image. According to documentation the default image viewer will show the image. (Which is supposed to be XV). But as soon as I run the code below where image is a filepath I get "sh: xv: not found".
from PIL import Image
im = Image.open(image)
im.show()
So I tried to install the XV package but can't find how to install it for Angstrom.
My question could either be "How to display images fullscreen with Python?" (To which the answer was supposed to be the code above). Or the question is "How can I get XV installed on Angstrom?" (What is the package name for opkg install)
I did search, but haven't found something that works...
Image.show() in PIL is more intended for debugging than actual, production use. It is hardcoded to call xv <temp-image-file-pil-creates>. You can hack around this (make a symbolic link called xv that will call some other image viewer), but it's still a rather bad way to go about it.
I don't know enough about the BeagleBoard to tell you the best/canonical way to display an image fullscreen, but if you got halfway there with PyGame, perhaps you can post your code and the community can help you fix the quality problem.
If the image is getting downscaled to fit the screen, you might look into using transform.smoothscale to scale the image manually (to avoid losing quality).

Categories

Resources