Java 比对两张图片的差异

GitHub - 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. Can be used for automation QA tests.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. Can be used for automation QA tests. - GitHub - 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. Can be used for automation QA tests.icon-default.png?t=N7T8https://github.com/romankh3/image-comparison

1、引用jar包

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

2、参考代码

/**
 * 图片比较演示 https://github.com/romankh3/image-comparison
 * 【Github官方图片,略有小改动】
 *
 * @author chendd
 * @date 2023/7/8 14:37
 */
public class GithubImageComparisonTest {
 
    public static void main(String[] args) {
        //加载图片
        BufferedImage expectedImage = ImageComparisonUtil.readImageFromResources("Expected.png");
        BufferedImage actualImage = ImageComparisonUtil.readImageFromResources("Actual.png");
        //对比两个图片
        ImageComparisonResult imageComparisonResult = new ImageComparison(expectedImage, actualImage).compareImages();
        String folder = ImageComparisonUtil.class.getClassLoader().getResource("").getPath();
        //存储图片和输出结果
        ImageComparisonUtil.saveImage(new File(folder , "Github图片对比结果.png") , imageComparisonResult.getResult());
        System.out.println("Github图片对比状态:" + imageComparisonResult.getImageComparisonState());

3、比对结果 


Expected Image

expected

Actual Image

actual

Result

result

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值