Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

isn't it simply this ?

int bits[] = { // lsb first !
    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
};

for (int j=0; j<8; j++) {
    int check=0;
    for (int i=0; i<8; i++) {
       check |= (bits[i+j*8]) << i;
    }
    int out = (int)(outMat.get(0,j)[0]);
    Assert.assertEquals(check, out);
}

(imho, you should not use Strings for this at all, and your Mat access is broken, counting backwards)

isn't it simply this ?

int capacity = 32 * 32;
double[] dataArr = new double[capacity];
for (int i = 0; i < capacity; ++i) {
    dataArr[i] = i;
}
Mat inMat = new Mat(32, 32, CvType.CV_8U);
inMat.put(0, 0, dataArr);
Mat outMat = new Mat();
Img_hash.pHash(inMat, outMat);

int bits[] = { // lsb first !
    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
};

for (int j=0; j<8; j++) {
    int check=0;
    for (int i=0; i<8; i++) {
       check |= (bits[i+j*8]) << i;
    }
    int out = (int)(outMat.get(0,j)[0]);
    Assert.assertEquals(check, out);
}

(imho, you should not use Strings for this at all, and your Mat access is broken, counting backwards)

isn't it simply this ?

int capacity = 32 * 32;
double[] dataArr = new double[capacity];
for (int i = 0; i < capacity; ++i) {
    dataArr[i] = i;
}
Mat inMat = new Mat(32, 32, CvType.CV_8U);
inMat.put(0, 0, dataArr);
Mat outMat = new Mat();
Img_hash.pHash(inMat, outMat);

int bits[] = { // lsb first !
    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
};

for (int j=0; j<8; j++) {
    int check=0;
    for (int i=0; i<8; i++) {
       check |= (bits[i+j*8]) << i;
    }
    int out = (int)(outMat.get(0,j)[0]);
    Assert.assertEquals(check, out);
}

NOTE: this compares bytes, not bits. if you want bits, try like this:

for (int j=0; j<8; j++) {
    int out = (int)(outMat.get(0,j)[0]);
    for (int i=0; i<8; i++) {
       int a = bits[i+j*8];
       int b = (out & (1<<i)) > 0 ? 1 : 0;
       Assert.assertEquals(a, b);
    }
}

(imho, you should not use Strings for this at all, and your Mat access is broken, counting backwards)

isn't it simply imho, you should not use Strings for this ?at all, and your Mat access is broken, counting backwards

int capacity = 32 * 32;
double[] dataArr = new double[capacity];
for (int i = 0; i < capacity; ++i) {
    dataArr[i] = i;
}
Mat inMat = new Mat(32, 32, CvType.CV_8U);
inMat.put(0, 0, dataArr);
Mat outMat = new Mat();
Img_hash.pHash(inMat, outMat);

int bits[] = { // lsb first !
    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
};

for (int j=0; j<8; j++) {
    int check=0;
    for (int i=0; i<8; i++) {
       check |= (bits[i+j*8]) << i;
    }
    int out = (int)(outMat.get(0,j)[0]);
    Assert.assertEquals(check, out);
}

NOTE: this compares bytes, not bits. if you want bits, try like this:

for (int j=0; j<8; j++) {
    int out = (int)(outMat.get(0,j)[0]);
    for (int i=0; i<8; i++) {
       int a = bits[i+j*8];
       int b = (out & (1<<i)) > 0 ? 1 : 0;
       Assert.assertEquals(a, b);
    }
}

(imho, you should not use Strings for this at all, and your Mat access is broken, counting backwards)