image-comparison

简介: image-comparison

人活在世,不过一场美丽的寄居。——简嫃曾

我们可以使用image-comparison来在java中进行两个文件的对比:

项目地址:https://github.com/romankh3/image-comparison

它会自动生成对比后带红框的对比图,还能返回这些正方形的信息

首先引入GAV

<dependency>
    <groupId>com.github.romankh3</groupId>
    <artifactId>image-comparison</artifactId>
    <version>4.4.0</version>
</dependency>

使用:

//load images to be compared:
     BufferedImage expectedImage = ImageComparisonUtil.readImageFromResources("expected.png");
     BufferedImage actualImage = ImageComparisonUtil.readImageFromResources("actual.png");
     //Create ImageComparison object and compare the images.
     ImageComparisonResult imageComparisonResult = new ImageComparison(expectedImage, actualImage).compareImages();
     //Check the result
     assertEquals(ImageComparisonState.MATCH, imageComparisonResult.getImageComparisonState());

这里是对比俩文件是否相同,在这个imageComparisonResult中还包含了其他的信息,这里就不一一列举了,可以在项目介绍中看到

如果我们要生成对比后的图,用下面的方式即可

//load images to be compared:
       BufferedImage expectedImage = ImageComparisonUtil.readImageFromResources("expected.png");
       BufferedImage actualImage = ImageComparisonUtil.readImageFromResources("actual.png");
       // where to save the result (leave null if you want to see the result in the UI)
       File resultDestination = new File( "result.png" );
       //Create ImageComparison object with result destination and compare the images.
       ImageComparisonResult imageComparisonResult = new ImageComparison(expectedImage, actualImage, resultDestination).compareImages();

resultDestination也可以传路径

相关文章
HALCON error #1302: Wrong value of control parameter: 2 in operator affine_trans_region
HALCON error #1302: Wrong value of control parameter: 2 in operator affine_trans_region
|
3月前
|
Python
UserWarning: Palette images with Transparency expressed in bytes should be converted to RGBA images
本文提供了解决PIL库中"Palette images with Transparency"警告的方法,通过将图片转换为'RGB'模式来消除透明通道的问题。
UserWarning: Palette images with Transparency expressed in bytes should be converted to RGBA images
|
4月前
|
Python
已解决:_tkinter.TcLError: couldn’t recognize data in image file “Image/nakamuraan.gif”
已解决:_tkinter.TcLError: couldn’t recognize data in image file “Image/nakamuraan.gif”
138 1
|
11月前
|
JavaScript
image-conversion
image-conversion
208 0
|
人工智能 编解码 自然语言处理
论文解读:Inpaint Anything: Segment Anything Meets Image Inpainting
论文解读:Inpaint Anything: Segment Anything Meets Image Inpainting
420 0
《AVPASS-Leaking-And-Bypassing-Anitvirus-Detection-Model-Automatically》电子版地址
AVPASS-Leaking-And-Bypassing-Anitvirus-Detection-Model-Automatically
58 0
《AVPASS-Leaking-And-Bypassing-Anitvirus-Detection-Model-Automatically》电子版地址
|
JSON Kubernetes Devops
kustomize (七) patches、patchesJson6902、patchesStrategicMerge详解
kustomize (七) patches、patchesJson6902、patchesStrategicMerge详解
成功解决ValueError: numpy.ufunc size changed, may indicate binary incompatibility. Expected 216 from C h
成功解决ValueError: numpy.ufunc size changed, may indicate binary incompatibility. Expected 216 from C h
成功解决ValueError: numpy.ufunc size changed, may indicate binary incompatibility. Expected 216 from C h
how to find the original page containing a given image
how to find the original page containing a given image
100 0
how to find the original page containing a given image