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包


    com.github.romankh3
    image-comparison
    4.4.0

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

Java 比对两张图片的差异_第1张图片

Actual Image

Java 比对两张图片的差异_第2张图片

Result

Java 比对两张图片的差异_第3张图片

你可能感兴趣的:(java,python,开发语言)