region with finder

Asked by Maniraj on 2017-12-09

Hi i am having one screenshot with specific region and i am trying to find one image inside that region it is possible

IMP.. Specific region will take screenshot in runtime and in that image we need to find expected image.

  WebElement elmt = driver2.findElement(By.xpath("//*[@id='window']"));
                Screenshot regionset = new AShot().takeScreenshot(driver, elmt);
  BufferedImage regionsetimage = regionset.getImage();
  ImageIO.write(regionset.getImage(), "PNG", new File("/Users/aathi/Desktop/testimage2.png"));
  Pattern Capimage = new Pattern(regionsetimage);
  Region reg1 = screen.find(Capimage);
  String a = reg1.toString();
  Finder f = new Finder("/Users/aathi/Desktop/testimage2.png");
             //Finder f = new Finder(a);
  Pattern image = new Pattern("/Users/aathi/Desktop/Sikuli/"+imageName);

This is always running even the image is not present in that region also can u give any better solution for this

My Aim is -- I need to find image in that bufferedimage which is set as region. i don't want to search for that image in web screen. i need to find or search for image in side that captured image which is captured as region in my localpath.

Kindly excepting your reply

Question information

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

Read about the result of Finder.find() in the docs

Maniraj (aathimaniraj) said : #2

Can you please share set of sample code in Java for finder with in the region it is very helpful for me.. I saw document my bad i am not able to understand Similarity concept.

They are following this type ---- f.find(image); //but it is not working for me.

My Aim is i am trying to find image inside region screenshot which is taken at run time and i need to verify in that screenshot not in webpage. pls help me to resolve this.

I need example with combination of Region and Finder

RaiMan (raimund-hocke) said : #3

String imagePath = "/Users/aathi/Desktop/" // the place where you have your images (should be a folder to not clutter the desktop)
WebElement elmt = driver2.findElement(By.xpath("//*[@id='window']"));
Screenshot regionset = new AShot().takeScreenshot(driver, elmt);
//Finder has a constructor with a buffered image
Finder window = new Finder(regionset.getImage()); // where to search in
Pattern testImage = new Pattern(new File(imagePath, testimage2.png)).getAbsolutePath)); // what to search
window.find(testImage) // search and prepare Finder for revealing result
Match found = null;
if (window.hasNext()) {
    found =
} else {
    // not found

With a mature IDE like Eclipse or IntelliJ IDEA you might inspect the SikuliX API and together with the docs just learn and find your way.

One more thing: you should get familiar with the SikuliX concept of ImagePath.

Maniraj (aathimaniraj) said : #4

Thank you raiman I will try this and let me know...

Maniraj (aathimaniraj) said : #5

Thank you raiman I will try this and let me know...

Maniraj (aathimaniraj) said : #6

Thank you raiman I will try this and let me know...

Maniraj (aathimaniraj) said : #7

For comment #3
1. It will find image in the captured region which is saved in local only ryt?
2. It will not find in the webscreen ryt?
3. Based on this concept there is no need of window needs to be active ryt?
4. For setting region screen will be active that's is fine after that no need of active ?

Kindly clear their doubts..

RaiMan (raimund-hocke) said : #8

--1: the captured region is not saved at all, since it is a BufferedImage, which is an in-memory representation. ... and yes, the Finder looks for images given by Finder.find(image) inside this in-memory image.
Remember: this in-memory image is created at time of
Screenshot regionset = new AShot().takeScreenshot(driver, elmt);
and does not change afterwards (it is a shot or in SikuliX idiom a capture)

--2: Ryt ;-) it does not look into the webscreen, but into the captured screen content according to --1

--3: Not ryt ;-) until this has happened:
Screenshot regionset = new AShot().takeScreenshot(driver, elmt);
the window must be active of course

--4: see --3

Maniraj (aathimaniraj) said : #9

--3 if the screenshot for region is taken and stored in local after that also window needs to active ? For finding image inside that region ? If yes means why?

Best RaiMan (raimund-hocke) said : #10

You are still not familiar with the concept of SikuliX: it is all about searching one static image inside another static image.

If we say, we are searching something in a screen region or some other screen area like a window, then in fact internally at that moment an in-memory static image of this area is produced (captured/shot) and further used.
With the features, that wait for some image to appear on the screen, this procedure of "capture and search" is repeated until found or timeout.

So if something has to be visible on the screen with respect to your workflow, then you have to take care for that.

Maniraj (aathimaniraj) said : #11

Thanks RaiMan, that solved my question.