Ask Your Question

Revision history [back]

phash of img_hash test fail in java

Hi dear: I turn the test example of img_hash into java, but test fail.

env:
opencv3.4.0 with module img_hash
JDK8
java test code:
@test
public void testHashCode() {
List codeList = Lists.newArrayList(
1,0,1,1,1,1,1,1,
0,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
0,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
0,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
0,1,1,1,1,1,1,1);
String expect = Joiner.on("").join(codeList);
int capacity = 32 * 32;
int value = 0;
double[] dataArr = new double[capacity];
for (int i = 0; i != capacity; ++i) {
dataArr[i] = value++;
}
Mat inMat = new Mat(32, 32, CvType.CV_8U);
inMat.put(0, 0, dataArr);
Mat outMat = new Mat();
Img_hash.pHash(inMat, outMat);
StringBuilder sb = new StringBuilder();
for (int row = outMat.rows() - 1; row >= 0; row--) {
for (int col = outMat.cols() - 1; col >= 0; col--) {
Double val = outMat.get(row, col)[0];
String origin = "00000000";
origin = origin + Long.toBinaryString(val.longValue());
sb.append(origin.substring(origin.length() - 8));
}
}
String binary = sb.toString();
Assert.assertEquals(expect, binary);
}

org.junit.ComparisonFailure: Expected :1011111101111111111111110111111111111111011111111111111101111111 Actual : 1111111111111110111111101111111011111110111111101111110011111111