cannot find image using find(image_path)

Asked by ONG YI CHONG

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:

[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(Imgproc.java:2612)
at org.sikuli.script.Finder2.doFindMatch(Finder2.java:357)
at org.sikuli.script.Finder2.doFind(Finder2.java:327)
at org.sikuli.script.Finder2.find(Finder2.java:79)
at org.sikuli.script.Finder.find(Finder.java:267)
at org.sikuli.script.Region.runFinder(Region.java:2889)
at org.sikuli.script.Region.doFind(Region.java:2827)
at org.sikuli.script.Region.find(Region.java:2327)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.b

ase/java.lang.reflect.Method.invoke(Method.java:564)
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

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

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

Revision history for this message
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 ?

Revision history for this message
RaiMan (raimund-hocke) said :
#3

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

Revision history for this message
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.

Revision history for this message
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.

Revision history for this message
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

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

... and please read to understand, how SikuliX works:
https://sikulix-2014.readthedocs.io/en/latest/basicinfo.html#sikulix-how-does-it-find-images-on-the-screen

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.

BTW:
what system?
what java?

Revision history for this message
ONG YI CHONG (calveeen) said :
#7

Im using sikuli IDE in python

Revision history for this message
ONG YI CHONG (calveeen) said :
#8

Im using sikuli IDE in python

Revision history for this message
ONG YI CHONG (calveeen) said :
#9

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

Revision history for this message
ONG YI CHONG (calveeen) said :
#10

Thanks for helping !

Revision history for this message
ONG YI CHONG (calveeen) said :
#11

Thanks for helping !

Revision history for this message
RaiMan (raimund-hocke) said :
#12

seems to be solved