1 | initial version |
Worked it out.
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#include <functional>
#include <openssl/md5.h>
using namespace std;
using namespace cv;
static void help()
{
}
char *str2md5(const char *str, int length) {
int n;
MD5_CTX c;
unsigned char digest[16];
char *out = (char*)malloc(33);
MD5_Init(&c);
while (length > 0) {
if (length > 512) {
MD5_Update(&c, str, 512);
} else {
MD5_Update(&c, str, length);
}
length -= 512;
str += 512;
}
MD5_Final(digest, &c);
for (n = 0; n < 16; ++n) {
snprintf(&(out[n*2]), 16*2, "%02x", (unsigned int)digest[n]);
}
return out;
}
int main(int argc, const char** argv)
{
help();
if (argc != 2)
{
return EXIT_FAILURE ;
}
string inputfile = argv[1] ;
Mat src = imread (inputfile, -1) ;
if (src.empty())
{
return EXIT_FAILURE ;
}
cout << str2md5((char*)src.data, (int)src.step[0] * src.rows) << " " << inputfile << endl ;
return 0;
}