Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imagesearch returns wrong coordinates #8

Open
ricvillagrana opened this issue Aug 6, 2019 · 7 comments
Open

imagesearch returns wrong coordinates #8

ricvillagrana opened this issue Aug 6, 2019 · 7 comments

Comments

@ricvillagrana
Copy link

I searched for the position of an image, as your example shows, and if it is on the top-left corner the position is ok, but as it gets far from there, it will increase the coordinates even doubling them.

I divided them by 2 and it is close to the actual position but not enough:

from imagesearch import *

pos = imagesearch('notif.jpg')

if pos[0] != -1:
    print("position : ", pos[0], pos[1])
    pyautogui.moveTo(pos[0]/2, pos[1]/2)
    pyautogui.click(button="left")
else:
    print("image not found")

I am using Mac OS, also I use 2 monitors, but the problem is still there if I only use one.

@drov0
Copy link
Owner

drov0 commented Aug 6, 2019

Hello, I've tested your code and it runs fine on my end (ubuntu 18, double monitors as well). Since you have a mac I assume that the problem might be related to your high resolution. I have never tested it with resolutions higher than 1920×1080.

I've had a guy in the past with a retina display that had errors and here's his comment :

"However I had troubles with retina display and the screenshot function that was returning a double resolution image.
Here is the code with simple retina support, tested only on Mac OS :
https://github.com/anthonyivol/python-imagesearch/blob/master/imagesearch.py
"

@drov0
Copy link
Owner

drov0 commented Aug 6, 2019

I've actually updated the lib with retina support, tell me how that goes for you :)

@ricvillagrana
Copy link
Author

Thank you so much for your quick response.
I rebased master but now the imagesearch does not find the image, it prints image not found.

I also commented the is_retina validation and it seems not to have changes in the result.

@drov0
Copy link
Owner

drov0 commented Aug 8, 2019

Huh, that's odd, can you save the screencap and see if your searched image is in it ? (uncomment im.save('testarea.png'))

@ricvillagrana
Copy link
Author

Yes it is. These are the images, the testarea, and the image to search.
testarea
img

@drov0
Copy link
Owner

drov0 commented Aug 8, 2019

The size of the logo you're trying to find must match the size of the logo on the screencap. This is not a fancy machine learning image searching that will search things that resemble the input image. What opencv does is basically take the input image and then look for something of the same size and more or less the same colored pixels (this is what the tolerance parameter does btw). and if your input image is bigger than the one that's displayed, then it won't find it.

here's an example of a screencap + logo that works :

image

image

@eagleEggs
Copy link

Here is an option: https://www.pyimagesearch.com/2015/01/26/multi-scale-template-matching-using-python-opencv/

But if you can click by a unique value (pixel) then you save a lot of cycles. You could even do a branching pixel check from a color to rule out other colors on the screen which may be the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants