cannot find image using find(image_path)

Asked by ONG YI CHONG on 2018-12-06

I am trying to understand Sikuli's Region.find(PS) method and I understand how to use it when i input a pattern object (image) . However, when i try to ask sikuliX to find the image given the path i i input, I always seem to get an error.

match = "/Users/ongyichong/Desktop/Screenshot_1544070692.png"
returnMatch = find(match)


[error] JythonScriptRunner: runPython: (match = "/Users/ongyichong/Desktop/Screenshot_1544070692.png"
returnMatch = find(match)
) raised: Traceback (most recent call last):
File "<string>", line 2, in <module>
at org.opencv.imgproc.Imgproc.matchTemplate_1(Native Method)
at org.opencv.imgproc.Imgproc.matchTemplate(
at org.sikuli.script.Finder2.doFindMatch(
at org.sikuli.script.Finder2.doFind(
at org.sikuli.script.Finder2.find(
at org.sikuli.script.Finder.find(
at org.sikuli.script.Region.runFinder(
at org.sikuli.script.Region.doFind(
at org.sikuli.script.Region.find(
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(
at java.b

org.opencv.core.CvException: CvException [org.opencv.core.CvException: cv::Exception: OpenCV(3.4.2) /Users/raimundhocke/SikuliX/OpenCV/opencv-3.4.2/modules/imgproc/src/templmatch.cpp:1107: error: (-215:Assertion failed) _img.size().height <= _templ.size().height && _img.size().width <= _templ.size().width in function 'matchTemplate'

The screenshot definitely exists in the path i specified. Please advice, or am i using the API wrongly ?

Question information

English Edit question
Sikuli Edit question
No assignee Edit question
Last query:
Last reply:
RaiMan (raimund-hocke) said : #1

apparently the image /Users/ongyichong/Desktop/Screenshot_1544070692.png is larger in pixels than the current screen size.

ONG YI CHONG (calveeen) said : #2

Hmmm, is there a way around it ? So my Screenshot has to be the same size as the image that was from the screen shot ?

RaiMan (raimund-hocke) said : #3

same size or smaller than the region/screen/image in that you are searching for it

ONG YI CHONG (calveeen) said : #4

Hmm, i changed the resolution of the screenshot to make it smaller but it still throws me the same error.

ONG YI CHONG (calveeen) said : #5

I made it pretty small and i think it should be samller than the size of the same image on screen.

RaiMan (raimund-hocke) said : #6

Not a matter of resolution, this only tells the system how many pixels per inch, but the pixels itself stay the same.
try this, and you should get more detailed information about shot and images

match = "/Users/ongyichong/Desktop/Screenshot_1544070692.png"
returnMatch = find(match)

... and please read to understand, how SikuliX works:

Another problem might be, that your shot was made on a HiDPI/Retina monitor with an external Image-Capture-Tool.
In this case, the image has double pixels in both directions. It has to be resized to 50%.

Use the SikuliX IDE to make your screenshots.

what system?
what java?

ONG YI CHONG (calveeen) said : #7

Im using sikuli IDE in python

ONG YI CHONG (calveeen) said : #8

Im using sikuli IDE in python

ONG YI CHONG (calveeen) said : #9

you are right about taking the screen shot using retina display.

ONG YI CHONG (calveeen) said : #10

Thanks for helping !

ONG YI CHONG (calveeen) said : #11

Thanks for helping !

RaiMan (raimund-hocke) said : #12

seems to be solved