Skip to content

Commit bac0c4a

Browse files
committed
Added Image-Comparison library.
1 parent 5eedd64 commit bac0c4a

File tree

6 files changed

+118
-0
lines changed

6 files changed

+118
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>4.1-testing</artifactId>
7+
<groupId>com.github.vedenin</groupId>
8+
<version>0.01</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>image-comparison</artifactId>
13+
14+
<description>This example to using Image-Comparison for testing code.</description>
15+
16+
<properties>
17+
<maven.compiler.version>3.3</maven.compiler.version>
18+
<image.comparison.version>3.1.1</image.comparison.version>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>com.github.romankh3</groupId>
24+
<artifactId>image-comparison</artifactId>
25+
<version>${image.comparison.version}</version>
26+
</dependency>
27+
</dependencies>
28+
29+
<build>
30+
<plugins>
31+
<plugin>
32+
<groupId>org.apache.maven.plugins</groupId>
33+
<artifactId>maven-compiler-plugin</artifactId>
34+
<version>${maven.compiler.version}</version>
35+
<configuration>
36+
<encoding>UTF-8</encoding>
37+
<source>${java.version}</source>
38+
<target>${java.version}</target>
39+
</configuration>
40+
</plugin>
41+
</plugins>
42+
</build>
43+
44+
</project>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.github.vedenin.imagecomparison;
2+
3+
4+
5+
import com.github.romankh3.image.comparison.ImageComparison;
6+
import com.github.romankh3.image.comparison.ImageComparisonUtil;
7+
import com.github.romankh3.image.comparison.model.ComparisonResult;
8+
import com.github.romankh3.image.comparison.model.ComparisonState;
9+
10+
import java.awt.image.BufferedImage;
11+
import java.io.File;
12+
import java.io.IOException;
13+
import java.net.URISyntaxException;
14+
15+
/**
16+
* Sample of the using Image-Comparison library.
17+
*/
18+
public class Sample {
19+
20+
public static void main(String[] args) throws IOException, URISyntaxException {
21+
// load the images to be compared
22+
BufferedImage expectedImage = ImageComparisonUtil.readImageFromResources("expected.png");
23+
BufferedImage actualImage = ImageComparisonUtil.readImageFromResources("actual.png");
24+
25+
// where to save the result (leave null if you want to see the result in the UI)
26+
File resultDestination = new File("result.png");
27+
28+
//Create ImageComparison object for it.
29+
ImageComparison imageComparison = new ImageComparison(expectedImage, actualImage, resultDestination);
30+
31+
//Can be used another constructor for it, without destination.
32+
new ImageComparison("expected.png", "actual.png");
33+
//or
34+
new ImageComparison(expectedImage, actualImage);
35+
36+
//Also can be configured BEFORE comparing next properties:
37+
38+
//Threshold - it's the max distance between non-equal pixels. By default it's 5.
39+
imageComparison.setThreshold(10);
40+
imageComparison.getThreshold();
41+
42+
//RectangleListWidth - Width of the line that is drawn in the rectangle. By default it's 1.
43+
imageComparison.setRectangleLineWidth(5);
44+
imageComparison.getRectangleLineWidth();
45+
46+
//Destination. Before comparing also can be added destination file for result image.
47+
imageComparison.setDestination(resultDestination);
48+
imageComparison.getDestination();
49+
50+
//MaximalRectangleCount - It means that would get first x biggest rectangles for drawing.
51+
// by default all the rectangles would be drawn.
52+
imageComparison.setMaximalRectangleCount(10);
53+
imageComparison.getMaximalRectangleCount();
54+
55+
//MinimalRectangleSize - The number of the minimal rectangle size. Count as (width x height).
56+
// by default it's 1.
57+
imageComparison.setMinimalRectangleSize(100);
58+
imageComparison.getMinimalRectangleSize();
59+
60+
//After configuring the ImageComparison object, can be executed compare() method:
61+
ComparisonResult comparisonResult = imageComparison.compareImages();
62+
63+
//Can be found ComparisonState.
64+
ComparisonState comparisonState = comparisonResult.getComparisonState();
65+
66+
//And Result Image
67+
BufferedImage resultImage = comparisonResult.getResult();
68+
69+
//Image can be saved after comparison, using ImageComparisonUtil.
70+
ImageComparisonUtil.saveImage(resultDestination, resultImage);
71+
}
72+
}

helloworlds/4.1-testing/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
<modules>
1515
<module>cucumber</module>
1616
<module>mockito</module>
17+
<module>image-comparison</module>
1718
</modules>
1819
</project>

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,7 @@ of Apache Hadoop. https://hive.apache.org/ .License: [Apache 2](http://www.apach
991991
1. [Unitils](http://www.unitils.org/) - Modular testing library for unit and integration testing. License: [Apache 2](http://www.apache.org/licenses/LICENSE-2.0). ![business friendly license](https://github.com/Vedenin/useful-java-links/blob/master/img/business-friendly.png?raw=true)
992992
1. [SeLion](https://github.com/paypal/SeLion) - Enabling Test Automation in Java. SeLion builds on top of TestNG and Selenium to provide a set of capabilities that get you up and running with WebDriver in a short time. It can be used for testing web and mobile applications, [![GitHub stars](https://img.shields.io/github/stars/paypal/SeLion.svg?style=social&label=Star&maxAge=2592000)](https://github.com/paypal/SeLion). License: [Apache 2](http://www.apache.org/licenses/LICENSE-2.0). ![business friendly license](https://github.com/Vedenin/useful-java-links/blob/master/img/business-friendly.png?raw=true)
993993
1. [cdp4j](https://github.com/webfolderio/cdp4j) - Web-automation library for Java. It can be used for automating the use of web pages and for testing web pages. [![GitHub stars](https://img.shields.io/github/stars/webfolderio/cdp4j.svg?style=social&label=Star&maxAge=2592000)](https://github.com/webfolderio/cdp4j) License: [MIT](https://opensource.org/licenses/MIT). ![business friendly license](https://github.com/Vedenin/useful-java-links/blob/master/img/business-friendly.png?raw=true)
994+
1. [Image-Comparison](https://github.com/romankh3/image-comparison) - Published on Maven Central Java Library that compares 2 images with the same sizes and shows the differences visually by drawing rectangles. Some parts of the image can be excluded from the comparison. [![GitHub stars](https://img.shields.io/github/stars/romankh3/image-comparison.svg?style=social&label=Star&maxAge=2592000)](https://github.com/romankh3/image-comparison) License: [The Unlicense](https://unlicense.org)
994995

995996
### 2. Code Coverage
996997
*Frameworks and tools that enable collection of code coverage metrics for test suites.*

0 commit comments

Comments
 (0)