Failed to find image pattern using Finder

Asked by nitin

I'm trying to compare two screenshots captured using selenium webdriver. I'm using Nightly SikuliX 1.1.0.

I tried using Finder.find method but every time it fails.

The Java code is as below:

String masterSetFilePath = String.format("%s%s.png", masterFolder, testCaseName);
String currentSetFilePath = String.format("%s%s.png", currentFolder, testCaseName);
Pattern masterPattern = new Pattern(masterSetFilePath);
Finder finder = new Finder(currentSetFilePath);
finder.findAll(masterPattern);
if(finder.hasNext())
          {
  org.testng.Assert.assertTrue(true, "Pattern Found");
  }
  else
   {
    throw new AssertionError("Test Case Failed during image comparison - Test Case Name " + testCaseName);
   }

It always go to else.

Also tried giving similar to find method

finder.find(masterPattern.similar((float) 0.9));

Question information

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

just made some tests with latest nightly:

print "***** starting testFinder"
Debug.off()
bs = App("Safari")
bs.focus(); wait(1)
img = capture(selectRegion()) # the base image

def compare(base, target):
  f = Finder(base)
  f.find(target)
  if f.hasNext():
    print "** found", f.next()
  else:
    print "** notFound"

print "*** should be found (same image)"
compare(img, img)

print "*** should be found (contained image)"
icon = capture(selectRegion()) # capture an image inside the base image
compare(img, icon)

print "*** should not be found (different image, same size)"
mIcon = find(icon)
icon2 = capture(mIcon.right(100).right(mIcon.w)) # capture an image with same size
compare(icon, icon2)

print "*** should not be found (same image, different size)"
mIcon = find(icon)
icon2 = capture(mIcon.grow(10)) # make image larger than base
compare(icon, icon2)

produces the following output:
***** starting testFinder
*** should be found (same image)
** found M[0,0 718x198]@S(S(0)[0,0 1920x1200]) S:1,00 C:359,99 [-1 msec]
*** should be found (contained image)
** found M[27,16 92x97]@S(S(0)[0,0 1920x1200]) S:1,00 C:73,64 [-1 msec]
*** should not be found (different image, same size)
** notFound
*** should not be found (same image, different size)
** notFound

Revision history for this message
nitin (nitin-ch170584) said :
#2

Do i take a latest nightly build? if so, what is the version and download link plz? Will it resolve what i want to achieve?

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

when using 1.1.0, you should always take the latest nightly depending on the documented fixes.

Start here: http://sikulix.com

But since you are programming in Java:
- if you use Maven, then you always have the latest build
- if not, then you have to setup a new sikulixapi.jar if needed

But the problems you have with Finder, are not with the build (nothing changed in this area the last months).

The above test script just tests the different possible cases:

size of target --- content
----------------------------------------
same --- same (found)
smaller --- contained (found)
smaller --- not contained (not in the test script)
same --- different (not found)
larger --- does not matter (not found)

so if the find fails in your situation you have one of the cases 3 - 5

Revision history for this message
nitin (nitin-ch170584) said :
#4

Hi RaiMan,

I tried with the Sikuli IDE similar example but still i could not get the positive result. I think there is some issue or bug with the nightly build for finder.

Here is what i have tried:

f=Finder("testcase1-6.png")
img= "testcase1-7.png"
f.find(img)

if f.hasNext():
    print "found: ", f.next()
else:
    print "false not found"
f.destroy

Here every time the if fails. and throws "false not found".

Both the images are same. Coz im using the same image comparision. This is causing my Java test script also fail.

The version of nightly is: sikulixsetup-1.1.0-20150615

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

the images are NOT the same, because they come from 2 different captures.

With this kind of test, you have to take care, that the second shot can surely be found in the first shot.

so this should say "found":

f=Finder("testcase1-6.png")
img= "testcase1-6.png"
f.find(img)

if f.hasNext():
    print "found: ", f.next()
else:
    print "false not found"
f.destroy

BTW: f.destroy should be f.destroy(), but is not needed anyways anymore.

Revision history for this message
nitin (nitin-ch170584) said :
#6

Here, I copied the script from the IDE. I could have shown you the same image if screenshot attachment would be here in this editor.

Since i copy the script from, the name of the image u see here is different as it got generated in .py file. I cannot keep the same, for say, "testcase1-6.png" in the same folder right.

I would still face this issue watever im trying. Please check it once.

By the way, the source of capture is same for the images. Since i just renamed the filename coz i can't keep the two files with same name in one folder ..right?

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

I am sorry and a little ashamed.

Against my usual procedure I did not ask about the system you are running on.
Usually I am testing on Mac - and there everything works well

… but not on Windows (where you are apparently running on, since you have these problems)

So I confirm: Finder in the way you are using it does not work currently on Windows.
I am on the way to fix it to be available in tomorrows build.

Meanwhile (if you want to and it helps you to get further) this workaround works:

instead of
Finder("image file.png")
use
Finder(Image.create("image file.png"))

instead of
f.find("image file.png")
use
f.find(Image.create("image file.png"))

but do not use it extensively - it is just some hack to get around the filename problem on Windows until tomorrow.

again: I apologize for being such blind and thank you for insisting.

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

ok, should work again with tomorrows build

Revision history for this message
nitin (nitin-ch170584) said :
#9

Hi Raiman,

I tried with latest build i.e., sikulixsetup-1.1.0-20150622. Still im facing this same issue. I could able to work with your work-around.

In the build i think it is not yet fixed. Please check again.

Thanks

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

just tested with the latest build from tonight: works

About in IDE (or bottom left) should show 2015-06-23_01:00nightly

(tested on Win8-64/Java7)

Can you help with this problem?

Provide an answer of your own, or ask nitin for more information if necessary.

To post a message you must log in.