[1.1.4] region.find(image): template size error (size region == size image)

Asked by ONG YI CHONG on 2018-12-12

I am trying to compare screenshots of the phone before and after a click. Ideally, after a click, I would wait for a moment to see if there is any change in UI, and if it detects a change then i would take a screenshot of it.

This is the function that i coded out .

def observe_and_click(phone_region, pixel_region, handler, observe_time):
    global i
    path = capture(phone_region,"/Users/ongyichong/SikuliX/Scripts","temp") # capture the current screenshot before click
    pixel_region.click() # make pixel click on region
    wait(0.5) # wait for UI transitions if any
    try:
        match = phone_region.find(path) # find a match for this
        #path_1 = capture(phone_region,"/Users/ongyichong/SikuliX/Scripts",str(i))
        print("similarity: " + str(match.getScore()))
    except FindFailed or CvException:
        # screenshots are dissimilar, take screenshot
        path_1 = capture(phone_region,"/Users/ongyichong/SikuliX/Scripts",str(i))
        i += 1

I dont know why the line match = phone_region.find(path) always throws this error:
/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'

Since I am using sikuli's capture function the image captured should be of similar pixels. Why there be a mismatch in the template size ?

Question information

Language:
English Edit question
Status:
Answered
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Last query:
2018-12-12
Last reply:
2018-12-12
RaiMan (raimund-hocke) said : #1

indeed looks odd ;-)
I have to check.

RaiMan (raimund-hocke) said : #2

cannot reproduce:

reg = Region(20, 120, 200, 200)
img = capture(reg, "img")
match = reg.find(img)
match.highlight(2)

run with Debug.on(3) and check the log

ONG YI CHONG (calveeen) said : #3

Hmm its sometimes shows error when i adjust the wait timing too short

RaiMan (raimund-hocke) said : #4

what about
--- run with Debug.on(3)

Can you help with this problem?

Provide an answer of your own, or ask ONG YI CHONG for more information if necessary.

To post a message you must log in.