如何在Java中比较两张图片?

huangapple go评论81阅读模式
英文:

How to compare two images in Java?

问题

以下是您提供的代码部分的中文翻译:

我已经尝试了下面的代码但出现了如下异常 -

public class TestCaseFile {
    public static void main(String [] args) throws IOException {
        String imgOriginal = "C:\\Users\\nn252j\\Desktop\\personal\\photos\\Output\\minionFloppedImage.jpg";
        String imgToCompareWithOriginal = "C:\\Users\\nn252j\\Desktop\\personal\\photos\\Output\\minionFloppedImage.jpg";
        String imgOutputDifferences = "new_screenshot_with_changes.jpg";

        ImageComparison imageComparison = new ImageComparison(10,10,0.05);

        if(imageComparison.fuzzyEqual(imgOriginal,imgToCompareWithOriginal,imgOutputDifferences))
            System.out.println("Images are fuzzy-equal.");
        else
            System.out.println("Images are not fuzzy-equal.");
    }
}

异常详细信息

Exception in thread "main" java.lang.NoClassDefFoundError: net/coobird/thumbnailator/Thumbnails
at org.frontendtest.components.ImageComparison.adaptImageSize(ImageComparison.java:105)
at org.frontendtest.components.ImageComparison.fuzzyEqual(ImageComparison.java:36)
at org.frontendtest.components.ImageComparison.fuzzyEqual(ImageComparison.java:23)
at TestCaseFile.main(TestCaseFile.java:12)


<details>
<summary>英文:</summary>

I have tried with below code but getting an exception as shown below -

    public class TestCaseFile {
        public static void main(String [] args) throws IOException {
            String imgOriginal = &quot;C:\\Users\\nn252j\\Desktop\\personal\\photos\\Output\\minionFloppedImage.jpg&quot;;
            String imgToCompareWithOriginal = &quot;C:\\Users\\nn252j\\Desktop\\personal\\photos\\Output\\minionFloppedImage.jpg&quot;;
            String imgOutputDifferences = &quot;new_screenshot_with_changes.jpg&quot;;
    
            ImageComparison imageComparison = new ImageComparison(10,10,0.05);
    
            if(imageComparison.fuzzyEqual(imgOriginal,imgToCompareWithOriginal,imgOutputDifferences))
                System.out.println(&quot;Images are fuzzy-equal.&quot;);
            else
                System.out.println(&quot;Images are not fuzzy-equal.&quot;);
        }
    }



**Exception Details**

    Exception in thread &quot;main&quot; java.lang.NoClassDefFoundError: net/coobird/thumbnailator/Thumbnails
    at org.frontendtest.components.ImageComparison.adaptImageSize(ImageComparison.java:105)
    at org.frontendtest.components.ImageComparison.fuzzyEqual(ImageComparison.java:36)
    at org.frontendtest.components.ImageComparison.fuzzyEqual(ImageComparison.java:23)
    at TestCaseFile.main(TestCaseFile.java:12)







</details>


# 答案1
**得分**: 1

以下是翻译好的内容:

你可能需要在Maven中添加以下依赖项:

```xml
<dependency>
  <groupId>net.coobird</groupId>
  <artifactId>thumbnailator</artifactId>
  <version>0.4.13</version>
</dependency>
英文:

You may need the following dependency in Maven:

&lt;dependency&gt;
  &lt;groupId&gt;net.coobird&lt;/groupId&gt;
  &lt;artifactId&gt;thumbnailator&lt;/artifactId&gt;
  &lt;version&gt;0.4.13&lt;/version&gt;
&lt;/dependency&gt;

huangapple
  • 本文由 发表于 2020年10月28日 02:40:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/64560956.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定