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

Issue with pyscreeze version 0.1.30 - ImageNotFoundException #110

Open
hayashi7w opened this issue Nov 17, 2023 · 7 comments
Open

Issue with pyscreeze version 0.1.30 - ImageNotFoundException #110

hayashi7w opened this issue Nov 17, 2023 · 7 comments

Comments

@hayashi7w
Copy link

hayashi7w commented Nov 17, 2023

Version Information:

pyscreeze version: 0.1.30 (Problematic), 0.1.29 (Problem Solved)
Operating System: Windows 10
Python Version: 3.12.0
Detailed Description of the Issue:
I encountered an issue with pyscreeze version 0.1.30 where it consistently threw an ImageNotFoundException despite the image being present on the screen. The error message indicated a high confidence level (0.999) in locating the image, but the image could not be found. After downgrading to pyscreeze version 0.1.29, the issue was resolved and the image was correctly identified.

Code Snippet to Reproduce the Issue:

import pyautogui as pg

img_path = "path_to_image.png"
location = pg.locateOnScreen(img_path)
if location:
    pg.click(location)
else:
    print("Image not found.")

Error Message and Stack Trace:

Exception has occurred: ImageNotFoundException
Could not locate the image (highest confidence = 0.999)
pyscreeze.ImageNotFoundException: Could not locate the image (highest confidence = 0.999)

Additional Context:
The same code and image file work perfectly with pyscreeze version 0.1.29. The issue seems specific to version 0.1.30. Any insights or resolutions would be greatly appreciated.

@mikigo
Copy link

mikigo commented Dec 11, 2023

Is opencv installed? If it is not installed, it is illogical.

@hayashi7w
Copy link
Author

Yes, OpenCV is installed.

@PieVagabonde
Copy link

I confirm the bug. With version 1.0.29 the code given by hayashi7w works. With version 1.0.30 we get the error message mentioned if the image is not found.

@GScrok
Copy link

GScrok commented Jan 29, 2024

Yes, I have the same problem, I had to return to the previous version 0.1.29

@aentwist
Copy link

Between the lack of git tags and commit message indication, the versioning is unclear. But there aren't that many commits, I checked based on the date and it turns out it's literally the last commit eeca245

@IanSapp128
Copy link

I too am experiencing this issue and when trying to use "locateAllOnScreen" with PyAutogui, it hits an exception. Thing is, a try/catch block doesn't catch it. Pyscreeze will still error out.

@aentwist
Copy link

aentwist commented Sep 6, 2024

I created https://github.com/aentwist/gamedriver to replace all image matching PyScreeze does. There were several important reasons for it, one of which was the interesting behavior around "confidence".

The error message indicated a high confidence level (0.999) in locating the image, but the image could not be found.

What is confidence?

Both our libraries use OpenCV template matching. It is not machine learning, but rather a 2D convolution. There is no confidence involved. There is only a threshold value that determines whether potential matches are "good enough" to be considered matches. In other words how close a match is, not how confident we are either in a match or that we matched. In some roundabout way, the "confidence" here is that threshold value. I cannot tell you exactly what it does after reading the source code. Just understand that increasing the "confidence" makes matching more strict - you'll be able to be very confident that any matches that do occur are correct. But with a "confidence" of 0.999, those matches probably won't occur at all; unless they are extremely precise it will result in a miss. It is no surprise that with such a high number matches are being missed.

As for the actual regression here, anyone can dig through the commit I linked, no further comment on that. Feel free to try out my library for matching purposes.

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

6 participants