findChanges has no function

Asked by Michael Böhm on 2020-08-20

I am using 2.0.4 on Windows10.

Following Script shows that findChanges has no function.

    img2=capture(RegNeu) # ensure same size
    f=Finder(Image.create(img)) #workaround from another bug
    f.findChanges(img2) # this has no function, also IDE does not highlight it as known function
    while f.hasNext():
        print "Found:",match

I did the implementation as described in , did the workaround for another known bug, but it still does not find differences in samesize pictures.

And please put on the wishlist to be able to compare Regions, not just imagefiles.


Question information

English Edit question
Sikuli Edit question
No assignee Edit question
Solved by:
Michael Böhm
Last query:
Last reply:
RaiMan (raimund-hocke) said : #1

should first be a question

Michael Böhm (badboisikulix) said : #3

Dear RaiMan.

Seriously I still believe it is a bug. because the IDE does not highlight the word "findChanges" as known command, and also all other finder functions work fine, just not findChanges.


RaiMan (raimund-hocke) said : #4

--- does not highlight the word "findChanges"
This is because the word is missing in the respective IDE support file (as many other features)

Relevant is, whether something like someRegionOrWhatever.someFunction() does not lead to a name error.

--- this is a findChanges test on Windows having the page open in Google Chrome and triggering changes by selecting a different tab

App.focus("Google Chrome")
#observe area in app window
reg = App.focusedWindow()
reg = reg.grow(-10, -540, -150, -30)
# put the app window in an startup state
if not reg.has("1598188841340.png"):
    btnOver = "btnOver.png"
    reg.wait("1598188674947.png", 10)
# capture startup state
img1 = capture(reg)
# chnage the content in the observed area
btnRepo = "img.png"
reg.wait("1598188724213.png", 10)
# capture changed state
img2 = capture(reg)

# evaluate changes
f = Finder(img1)
changes = f.findChanges(img2)
print "changes:", len(changes)
changed = Region(0, 0, reg.w, reg.h)
if len(changes) > 0:
    changed = changes[0]
    if len(changes) > 1:
        for change in changes[1:]:
            changed = changed.union(change)
changed = Region(reg.x + changed.x, reg.y + changed.y, changed.w, changed.h)

The result is 29 changes, which result in a changed area union in the right side of the page (as expected).

Hence, findChanges works as expected.

Be aware: in the current implementation (which surely has to be enhanced ;-) this is the safest way:


which in my testcase is assured by using capture(reg).

Michael Böhm (badboisikulix) said : #5

Dear RaiMan,

Thanks for the script, it helped me a lot.
Following was my mistake:
*) This part of the script did not print out the matches. Your solution of looping through works fine.

while f.hasNext(): # does NOT work, please review your docs
    print "Found:",match

(I copied from your documentation Please revise your docs.)

*) I further found an issue in your above script:
On my PC (2.0.4) I needed to use:
f = Finder(Image.create(img1))

to make it work. (I know its a bug, but for completeness sake).

*) as the documentation and samplescripts for findChanges are quite difficult to find, here is my working example to compare images on the screen.

*) documentation of
    f.setFindChangesPixelDiff(40)# to adjust PIXEL_DIFF # on documentationpage THIS is missing (typing error)
    f.setFindChangesImageDiff(5)# to adjust IMAGE_DIFF - seems to have no function at all, I did not find any differences in changing it to any value

It lets you select a region, finds the right region on the left side of that region, finds all the changes, filters out the smaller ones and double matches and compares the results to doublecheck. Thats needed if these images are not totally the same bit-wise.
I hope this helps somebody.


    Settings.MinSimilarity = 0.85 # for the doublecheck

    for match in matches:
    for match in matches:
        if not RegNeu.exists(capture(match)):
           print match
           print RegNeu.getLastMatch()

def checkDifference(Reg,RegNeu,size=30):
    print Reg,RegNeu
    RegNeu.setW(Reg.getW()) # ensure same size
    RegNeu.setH(Reg.getH()) # ensure same size

    f = Finder(Image.create(img1)) # Image.create due to a bug, might not be needed later
    #both images are converted to grayscale
    #only pixels whose gray value differs +-3 (PIXEL_DIFF) are looked at
    #if more than 5 pixels are detected (IMAGE_DIFF) a change is assumed
    f.setFindChangesPixelDiff(40)# to adjust PIXEL_DIFF
    f.setFindChangesImageDiff(5)# to adjust IMAGE_DIFF - seems to have no function at all
    changes = f.findChanges(img2)
    print "changes:", len(changes)

    for i,match in enumerate(changes[1:]):
            if match.getW()>size or match.getH()>size:
                print "Right size:",i,match
                for t,compareMatch in enumerate(matches):
                    if biggerMatch:
                        if biggerMatch==compareMatch:
                            addMatch=False # drop adding smaller ones
                if addMatch: matches.append(match)

    print "real changes:", len(matches)
    return matches

def isRegionOverlap(Reg1, Reg2): # find out wether Region1 overlaps Region2
      if (R1[0]>=R2[2]) or (R1[2]<=R2[0]) or (R1[3]<=R2[1]) or (R1[1]>=R2[3]):
         return False
         return True

def isRegionCompleteOverlap(Reg1, Reg2): # find out wether Region1 is completely inside Region2 or viceversa

      print Reg1,Reg2
      print R1,R2
      if (R1[0]<=R2[0]<=R2[2]<=R1[2]) and (R1[1]<=R2[1]<=R2[3]<=R1[3]):
         return Reg2 #True return bigger one
               if (R2[0]<=R1[0]<=R1[2]<=R2[2]) and (R2[1]<=R1[1]<=R1[3]<=R2[3]):
                      return Reg1 #True return bigger one
                      return False