2

I need to get the co-ordinates of matched image within the actualImage so that I can perform operations on it. However, I tried below two approaches,but both doesn't seem to work:

Approach 1: Using below, I'm able to find a match but co-ordinates returned are just the width & height of image to be matched(which I already know). I want to get the position of the same within actual image.

    BufferedImage actualImg = ImageIO.read(new File("C:/Images/SrcImg.PNG"));
    ImageTarget actualTgt = new ImageTarget(actualImg);
    BufferedImage searchImg = ImageIO.read(new File("C:/Images/TgtImg.PNG"));       
    ImageTarget searchTgt = new ImageTarget(searchImg);
    ScreenRegion scrReg = new StaticImageScreenRegion(actualTgt.getImage());
    ScreenRegion resReg = scrReg.find(searchTgt);
    ScreenLocation center = resReg.getCenter();
    System.out.println(":getElementFromImage: x_loc,y_loc =["+center.getX()+","+center.getY()+"]");

Approach 2: In below code I tried with sikulix Finder. However, with this src.hasNext() returned true BUT src.next() threw nullpointer exception.Not sure what is the problem here:

    Finder src = new Finder("C:/Images/SrcImg.PNG");
    Pattern pat = new Pattern("C:/Images/TgtImg.PNG").similar(0.5);
    src.find(pat);
    Match m;
    while( src.hasNext()) 
        m = src.next();
    src.destroy();

java.lang.NullPointerException
at org.sikuli.script.Finder.next(Finder.java:484)
at com.work.ImageFinder.main(ImageFinder.java:38)

I already spent good amount of time to make this work. Any help would be much appreciated.

Thanks!

nagpai
  • 169
  • 1
  • 3
  • 15
  • Finally it worked with 2nd approach, with below change - had to pass the Region as well to Finder: Finder src = new Finder("C:/Images/SrcImg.PNG", new Region(0,0,,)) Thanks for this answer: https://stackoverflow.com/questions/13229705/is-it-possible-to-use-sikuli-to-assert-that-images-are-the-same-in-gui-less-mode – nagpai Oct 08 '18 at 05:59

1 Answers1

1

It works fine after passing the Region to Finder like below:

Finder src = new Finder("C:/Images/SrcImg.PNG", new Region(0,0,<width>,<height>))
Pattern pat = new Pattern("C:/Images/TgtImg.PNG").similar(0.5);
src.find(pat);
Match m;
while( src.hasNext()) 
    m = src.next();
src.destroy();

More details can be found below link: Is it possible to use Sikuli to assert that images are the same in GUI-less mode?

nagpai
  • 169
  • 1
  • 3
  • 15