From 45451a99cf91bd713587cdc41560091ccef0cfb9 Mon Sep 17 00:00:00 2001 From: ZhouYixun <291028775@qq.com> Date: Thu, 10 Nov 2022 22:34:15 +0800 Subject: [PATCH] fix: same pic width similar fail --- .../org/cloud/sonic/vision/cv/SimilarityChecker.java | 10 ++++++++-- src/test/java/org/cloud/sonic/vision/cv/CVTest.java | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/cloud/sonic/vision/cv/SimilarityChecker.java b/src/main/java/org/cloud/sonic/vision/cv/SimilarityChecker.java index 40a7294..2117ec7 100644 --- a/src/main/java/org/cloud/sonic/vision/cv/SimilarityChecker.java +++ b/src/main/java/org/cloud/sonic/vision/cv/SimilarityChecker.java @@ -29,21 +29,27 @@ import static org.bytedeco.opencv.global.opencv_core.*; import static org.bytedeco.opencv.global.opencv_imgcodecs.imread; import static org.bytedeco.opencv.global.opencv_imgproc.GaussianBlur; +import static org.bytedeco.opencv.global.opencv_imgproc.resize; public class SimilarityChecker { private Logger logger = new Logger(); public double getSimilarMSSIMScore(File file1, File file2, Boolean isDelete) { Mat i1 = imread(file1.getAbsolutePath()); + Mat n = new Mat(); Mat i2 = imread(file2.getAbsolutePath()); - if (i1.size().get() != i2.size().get()) { + Size s = new Size(); + s.height(i2.arrayHeight()); + s.width(i2.arrayWidth()); + resize(i1, n, s); + if (n.size().get() != i2.size().get()) { return 0; } double C1 = 6.5025, C2 = 58.5225; int d = opencv_core.CV_32F; Mat I1 = new Mat(); Mat I2 = new Mat(); - i1.convertTo(I1, d); + n.convertTo(I1, d); i2.convertTo(I2, d); Mat I2_2 = I2.mul(I2).asMat(); Mat I1_2 = I1.mul(I1).asMat(); diff --git a/src/test/java/org/cloud/sonic/vision/cv/CVTest.java b/src/test/java/org/cloud/sonic/vision/cv/CVTest.java index fb50ed7..85d4ff4 100644 --- a/src/test/java/org/cloud/sonic/vision/cv/CVTest.java +++ b/src/test/java/org/cloud/sonic/vision/cv/CVTest.java @@ -35,6 +35,7 @@ public void testTem() throws Exception { @Test public void testSimi() { SimilarityChecker similarityChecker = new SimilarityChecker(); + Assert.assertTrue(similarityChecker.getSimilarMSSIMScore(before, tem, false) > 0); Assert.assertTrue(similarityChecker.getSimilarMSSIMScore(before, s, false) > 0); } }