Skip to content

Commit

Permalink
fix: same pic width similar fail
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhouYixun committed Nov 10, 2022
1 parent 9477d8f commit 45451a9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/main/java/org/cloud/sonic/vision/cv/SimilarityChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/test/java/org/cloud/sonic/vision/cv/CVTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 45451a9

Please sign in to comment.