Ask Your Question
0

Phash Algorithm in img_hash

asked 2019-11-11 01:19:23 -0600

jlok gravatar image

updated 2019-11-11 01:19:49 -0600

I want to get the phash with opencv on Android then compare to a database of image phashes on a server.

  1. Is the phash algorithm in opencv img_hash the same as one from phash.org at all?

  2. I see img_hash.phash has compute function which just converts a mat to an output mat. How do I get the string representation of this output mat to then run against my phash database? This is what I have but I am getting some unrecognizable characters.

:

Mat outMat = new Mat();
phash.compute(inMat, outMat);
byte[] data = new byte[outMat.rows() * outMat.cols()];
outMat.get(0, 0, data);
String hashString = new String(data, StandardCharsets.UTF_8);
edit retag flag offensive close merge delete

Comments

it IS called a "bitstring", but no, it's not a java String at all.

berak gravatar imageberak ( 2019-11-11 01:43:57 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-11-11 01:42:27 -0600

berak gravatar image

updated 2019-11-11 02:01:19 -0600

  1. it's a clean-room rewrite, due to license issues.

  2. phash return 64 bits, that you have to compare to another phash value using e.g. the hamming norm.

while the original phash lib returns an int64(and you have to come up with your own comparison) , opencv returns a [1x8] CV_8U Mat (that's 64 bits, too !).

you're might use it like this:

Mat img1 = ...
Mat img2 = ...

Mat hash1 = new Mat();
phash.compute(img1, hash1);

Mat hash2 = new Mat();
phash.compute(img2, hash2);

double bitDist = phash.compare(hash1, hash2);
// same as:
//double bitDist = Core.norm(hash1, hash2, Core.NORM_HAMMING);
edit flag offensive delete link more

Comments

Thanks for the info berak. I'm trying to save the phash as a string and compare it on my server using my own hamming comparison and not with opencv's compare function. My server will use the original phash. If I convert opencv's phash mat to int64, I assume it is not the same as the int64 result from the original phash. Is that correct? Maybe this is what you meant by clean-room but I am not really familiar with the term.

jlok gravatar imagejlok ( 2019-11-12 22:18:04 -0600 )edit

If I convert opencv's phash mat to int64, I assume it is not the same as the int64 result from the original phash.

i'd think so, too, unfortunately.

"clean room" means: rewrite from scratch.

berak gravatar imageberak ( 2019-11-13 01:04:45 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-11-11 01:19:23 -0600

Seen: 885 times

Last updated: Nov 11 '19