Python 3.6.3 pyautogui.locateOnScreen not working - python

I have a "find.png" (attached)
The pyautogui.locateOnScreen is returning None, even after 20 screenshots!!!!
Using interpreter (code attached)
Note: 1) the image having the line, "import pyautogui as auto", is "find.png"
2)I have "find.png" in the same directory, it is founded( checked with PIL- Image)

After struggling with this forever also, finally figured out that you either use command line or print screen button with the windows key to take the screenshot. Using the snipping tool does not work
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')

Try this:
location = pyautogui.locateOnScreen('testing.png', confidence =.8)

None simply means that PyAutoGui was unable to find your image on the screen, do remember the window is active where find.png was sampled from.
If this doesn't work out then I believe the resolutions(from when you took the sample and the monitor used by you) are different.
Let us know if you face any problem.

Related

Python Pillow Image.show() Path Issue?

Honest warning—I'm a total beginner.
I'm using Python 3.8.2 in IDLE and sometimes in Spyder.
My goal: to open an image (located in a folder) in Preview using Pillow
My code:
from PIL import Image
my_image = Image.open("flower.jpg")
my_image.show(r"/Users/User/Desktop/flower.jpg")
I run this, and it works! But it only works if the jpg is on the Desktop. I want to put the image in a folder. So I changed my last line of code to something like this:
my_image.show(r"/Users/User/Desktop/folder/flower.jpg")
I put the image in the folder, run the program, and get this error:
**FileNotFoundError: [Errno 2] No such file or directory: 'flower.jpg'**
Oddly, if I put the jpg back onto the Desktop and still use the path with "folder" in it, the program runs successfully and shows me the image.
Is this a problem with the path? How can I use Image.show() to open an image that is located somewhere other than the Desktop?
Thank you!
If you want to open and view an image using an absolute path, you'll have to change this line:
my_image = Image.open(path_to_image_dir)
You've incorrectly passed a string to PIL.Image.show. This doesn't throw an error, since PIL.Image.show happens to take an optional string parameter title, which it will use as a title in the image window. Don't pass any parameters to show, and change "flower.jpg" in the line above to the actual path.

How to use the ImageGrab.grab().load() function or any other function to get pixel updates?

I have been trying to check if a pixel on the screen is changing. What do I need to do?
I have surfed the internet for a long time with no success. I have experimented with the code given on the net, and found out that my code is only giving data from the screen that was open when the code was run. ie, if the screen was white when the code was run, it will read pixels from the white screen, even though the screen color already changed.
from PIL import ImageGrab
px=ImageGrab.grab().load()
m=px[613,296]
print(m)
while 1:
if m!=px[613,296]:
m=px[613,296]
print(m)
I ran the code and started a video, I expected the values to keep changing but all I got was (255,255,255) (the white screen of the idle) I also tried to change the screen manually.
I tried runing the code without console and print the output without the while loop in a text file, I got correct values.But the task I need to complete needs to run the code several times to check if pixel updates. How should I accomplish this?
This works for me:
#!/usr/bin/env python3
from PIL import ImageGrab
while True:
px=ImageGrab.grab().load()
m=px[613,296]
print(m)
I think it will be faster if you just grab one pixel though by specifying a bounding box like this so you only grab one pixel:
#!/usr/bin/env python3
from PIL import ImageGrab
while True:
screen=ImageGrab.grab(bbox=(613,296,614,297))
px = screen.load()
m=px[0,0]
print(m,screen.size)

How to use python to export the bake image form blender

I want to make some operationi automatic.But I met some trouble in export the image after I bake it.At first I try to use "bpy.ops.object.bake_image()" to bake the image.But the result image can not be active in uv editor.
The bake was success,but the result image didn't appear in the uv editor.It need selected so that I could export the file.
So I search the document , and found the other command "bpy.ops.object.bake()".It have a parameter "save_mode",but I still met some obstacle in using this command.It always point me out that " RuntimeError: error: No active image found in material "material" (0) for object "1.001" ".
Here is the official document about this two command:
https://docs.blender.org/api/blender_python_api_2_78a_release/bpy.ops.object.html?highlight=bake#bpy.ops.object.bake
Can anyone try to give me some solution or some advice that how can I make this thing right.
Many of blenders operators require a certain context to be right before they will work, for bpy.ops.image.save() that includes the UV/Image editor having an active image. While there are ways to override the current context to make them work, it can often be easier to use other methods.
The Image object can save() itself. If it is a new image you will first need to set it's filepath, you may also want to set it's file_format.
img = bpy.data.images['imagename']
img.filepath = '/path/to/save/imagename.png'
img.file_format = 'PNG'
img.save()

python module ffpyplayer showing or displaying video frames to screen

Using python module ffpyplayer, How can I see the frames or get the img object to display or show the video image/frames to the screen?, in the tutorial that I followed, it seems very simple, it reads the frames and plays oudio but (does not display) any video image or frame to the screen, only if I add the (print img, t) will print the frame info to the screen but not video image is displayed on the screen.
I being following tutorials from: https://pypi.python.org/pypi/ffpyplayer, and here: http://matham.github.io/ffpyplayer/player.html, and searched google but the only relevant results point to the same info, I am somewhat new to programming and python, and so maybe I am missing something that seems to be very simple but I can't figure it out myself.
I am using: windows 7 64bit, python 2.7.11 32bit.
Any Help will be appreciated thank you very much.
from ffpyplayer.player import MediaPlayer
vid = 'test_video.flv'
player = MediaPlayer(vid)
val = ''
while val != 'eof':
frame, val = player.get_frame()
if val != 'eof' and frame is not None:
img, t = frame
print img, t #This prints the image object
# display img #This does nothing!
Kivy already provides such a video player, based on ffpyplayer, for you.
It also has the necessary threads already setup for you, to deal with buttons, file reading, audio and timing.
Check this page:
https://kivy.org/docs/api-kivy.uix.videoplayer.html
To install kivy:
https://kivy.org/docs/installation/installation.html
Then you might wish to take a look at the code in:
<< python_path >>\lib\site-packages\kivy\uix\videoplayer.py
That example could be rather complex, so you can also look at this url:
How to play videos from the web like youtube in kivy
Finally, in case Kivy complains that you only have opengl 1.1 (as happened to me), you might try adding the following lines to your code:
from kivy.config import Config
Config.set('graphics', 'multisamples', '0')
These solved the problem to me.

OpenCV -> Python - image window does not close

I need the user input after showing an image, but the problem is that the image window will not close and will freeze. Do you have some solution or alternative that I can use to get the user input?
Code:
import cv2
img = cv2.imread("begin.jpg")
cv2.imshow("test",img)
cv2.destroyAllWindows()
raw_input("test:")
Problem: Window that show image will not close
Cause: raw_input(). Removing the raw_input() the window closes as expected.
I expect more than one character from the user.
Thank you so much
I had the same problem: I found the next info in openCV DevZone, it looks like a bug: http://code.opencv.org/issues/2911 it works for me.

Categories