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

Image Match return True when the images have different color. #140

Open
gzll opened this issue Nov 15, 2018 · 4 comments
Open

Image Match return True when the images have different color. #140

gzll opened this issue Nov 15, 2018 · 4 comments

Comments

@gzll
Copy link

gzll commented Nov 15, 2018

method = cv2.TM_CCOEFF_NORMED

the app gui have some image buttons, when click them, their color will become yellow from blue.
tradeonly_selected
tradeonly
the find() or exists() function will return the match info, when the button is blue, and the match image is yellow, this is incorrect.
but if inverse, the button is yellow, and the match image is blue, the function doesn't find anything. this is correct.
why?
I compare lackey with SikuliX1's source code (doFindMatch() in Finder2.java), but cannot get any idea.

@glitchassassin
Copy link
Owner

Lackey (and Sikuli, if I'm not mistaken) converts the images to greyscale for comparison to improve performance. If you're interested in checking the color of a point, you can try using the Location.getColor() method.

@glitchassassin
Copy link
Owner

For reference, the code snippet you linked is to the older naive matcher; the Pyramid matcher, based on the same algorithm Sikuli uses, is the one that converts to greyscale first:

class PyramidTemplateMatcher(object):
""" Python wrapper for OpenCV's TemplateMatcher
Uses a pyramid model to optimize matching speed
"""
def __init__(self, haystack):
self.haystack = cv2.cvtColor(haystack, cv2.COLOR_BGR2GRAY) # Convert to grayscale
self._iterations = 3 # Number of times to downsample
def findBestMatch(self, needle, similarity):
""" Finds the best match using a search pyramid to improve efficiency
Pyramid implementation unashamedly stolen from https://github.com/stb-tester/stb-tester
*Developer's Note - Despite the name, this method actually returns the **first** result
with enough similarity, not the **best** result.*
"""
needle = cv2.cvtColor(needle, cv2.COLOR_BGR2GRAY) # Convert to grayscale

@gzll
Copy link
Author

gzll commented Nov 16, 2018

Got, Convert to grayscale for performance reason.
I test the scenario in lackey and SIKULIX1, but results is very different.
the scenario: the blue image button, compared with a blue image button screen cropped, and a yellow one.
lackey: if a blue crap, the confidence is 1.0, if yellow, it is something like 0.9995211958885193.
SIKULIX1(test with the "pattern setting"'s "Matching Preview" GUI): if blue, 0.99, if yellow, never matched, but when the confidence is down below 0.4, the matching is another yellow image button on the GUI.
so I think SIKULIX1 maybe still keeping the BGR channels for matching.
https://github.com/RaiMan/SikuliX1/blob/98ac9872e6d186c699cebcef1dc44e72dc17f87a/API/src/main/java/org/sikuli/script/FindInput2.java#L213
https://github.com/RaiMan/SikuliX1/blob/98ac9872e6d186c699cebcef1dc44e72dc17f87a/API/src/main/java/org/sikuli/script/Finder2.java#L605
https://github.com/RaiMan/SikuliX1/blob/98ac9872e6d186c699cebcef1dc44e72dc17f87a/API/src/main/java/org/sikuli/script/Finder2.java#L349

@glitchassassin
Copy link
Owner

At a casual glance, I think this is related to improvements noted in #136, where Sikuli now supports transparent images as masks. I'll do some research on this.

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

No branches or pull requests

2 participants