Find the Best Possible match

Asked by Chetan

we use findbest to find an image.
now on vm sometime it fails as the image match is less than 70% which is correct and expected due to slightly different resolution

however lets say if the image match is 50%. now we wish to the area. image where the match was 50% so that we can replace the current image with new one so that next time it would match 100%

any pointers would be appreciated

Question information

English Edit question
SikuliX Edit question
No assignee Edit question
Solved by:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :

You have to write a function, that:
- captures the area of the match (result temp image file)
- overwrites the original image (file system move)
- resets the Image cache (Image.reset())

Revision history for this message
Chetan (cshamdas) said :

Thanks raiman for the response. can you please elaborate on point 1 - captures the area of the match (result temp image file)

below is the code we use

we use match=SearchRegion.findBest(name) // this gets us the match rate or None

now when match rateis <70( default) then None is returned. however logs show that can image matched with 58% match rate( see debug logs)

in this case we need to have the image location that had 58% match rate so that we can use that
how can we so that can you please help with pointers


debug logs showing 58% match rate
[debug] Image: reused: 1629714875056.png (file:/C:/Perf/Work/Groups/AntiPirates/PDFNext/Automations/FeatTests/FEAT/Framework_Testing/TestFiles/VerifyInvalidPageNumber.sikuli/1629714875056.png)
[debug] Finder2: makeMat: INT_RGB (1280x360)
[debug] Finder2: makeMat: 3BYTE_BGR (499x144)
[debug] Finder2: doFindImage: start (stdDev: 88.6009 mean: 713.952878)
[debug] Finder2: doFindImage: in original: %58.1349 (?70) 32 msec
[debug] Finder2: doFindImage: end 33 msec
[debug] findAnyCollect: all SubFindRuns finished

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

match = findBest(...) # the match region
shot = None
if match:
    shot = capture(match)

Revision history for this message
Chetan (cshamdas) said :

Thanks RaiMan, that solved my question.