Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to convert cv::Mat to std::string and hash it using MD5 ?

I need to find the repeated images (exact same, this is not a image similarity problem) by hashing. So I tried something like this, but this seems not right.

Mat src = imread (inputfile, -1) ;

char* rawPtr = new char[src.step[0] * src.rows] ;
memcpy(rawPtr, (char*)src.data, src.step[0] * src.rows) ; // is this all the data ??
string rawdata(rawPtr) ;

cout << str2md5(rawPtr, strlen(rawPtr)) << endl ;

My file is CV_16UC3, 1624 by 1236 , 3 channels, src.step[0] * src.rows is the bytes number of the whole image 12043584 bytes, however strlen(rawPtr) returns 5739852 chars, and these don't match.

So the md5 value I got is not right. I would like to know how to efficiently and correctly convert cv::Mat data into a string.

click to hide/show revision 2
retagged

updated 2013-09-20 03:15:04 -0600

berak gravatar image

How to convert cv::Mat to std::string and hash it using MD5 ?

I need to find the repeated images (exact same, this is not a image similarity problem) by hashing. So I tried something like this, but this seems not right.

Mat src = imread (inputfile, -1) ;

char* rawPtr = new char[src.step[0] * src.rows] ;
memcpy(rawPtr, (char*)src.data, src.step[0] * src.rows) ; // is this all the data ??
string rawdata(rawPtr) ;

cout << str2md5(rawPtr, strlen(rawPtr)) << endl ;

My file is CV_16UC3, 1624 by 1236 , 3 channels, src.step[0] * src.rows is the bytes number of the whole image 12043584 bytes, however strlen(rawPtr) returns 5739852 chars, and these don't match.

So the md5 value I got is not right. I would like to know how to efficiently and correctly convert cv::Mat data into a string.