英文:
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 = "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 Details**
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>
# 答案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:
<dependency>
<groupId>net.coobird</groupId>
<artifactId>thumbnailator</artifactId>
<version>0.4.13</version>
</dependency>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论