Wednesday 17 October 2018

How to verify part of image in full image using Sikuli?

How to verify part of image in full image using Sikuli?



Let us assume in the application under test, we have a sub image / icon which needs to be verified for presence in main page. Here we want to verify image and not image attributes like src and so on. For verifying src attributes we can use getAttribute() method of Selenium and check whether it is containing expected value. 

To verify exact image presence we can use Sikuli tool. 

Sikuli is image recognition tool. Let us assume we have 2 file images. 

1. sub image / icon. 
2. main image

To use Sikuli, we need Sikuli libs imported in eclipse project. For eg: sikulixapi.1.1.3.jar (http://www.sikuli.org/)

(i) First we can define the Pattern ref object using Pattern class in Sikuli. 
String file_loc ="C:\\Images";
Pattern subImage= new Pattern(file_loc+"\\subImage2.PNG");

(ii) Using Finder class of Sikuli we can create object related to main image:

Finder finder = new Finder(ImageIO.read(new File(file_loc+"\\mainImage.png")));

(iii) And using find() method of Finder class we will know whether subimage is present in main image or not.

finder.find(subImage);

if(finder.hasNext())
{
System.out.println("Found the subImage");
}
else
{
System.out.println("Didnt Found the subImage");
}

Note: This similar logic can be used to compare 2 images whether they are equal or not.

Also, if your project requirement is to check whether 2 images are exactly equal.

Then you can use exact() at the pattern like this:

subImage.exact(); // which will verify for exact image presence in main image / other image. 

Similarly if your requirement is to check 70% image match or x percentage, then you can use similar(0.7f) or any floating value. For eg:

subImage.similar(0.7f); // will check for 70% match in main image / other image. 

if you have any questions about this do write in comment below. 

Hope this blog has been useful to you. If yes do follow my blogs by entering your email by 
clicking on "Follow" (blue) button. 

You can as well explore my 

Youtube Channel: https://www.youtube.com/user/srinivaskinik

And 

facebook page: https://www.facebook.com/srinivaskinikalmady/

Thank you.


No comments:

Post a Comment

How to schedule RFT (Rational Functional Tester) scripts to run using Jenkins / schedule

How to schedule RFT (Rational Functional Tester) scripts to run using Jenkins / schedule 1. Create a batch file with following content ...