-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathreference.cpp
63 lines (53 loc) · 2.18 KB
/
reference.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Tutorial and code from
// https://qtandopencv.blogspot.com/2016/06/introduction-to-image-hash-module-of.html
#include <opencv2/core.hpp>
#include <opencv2/core/ocl.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/img_hash.hpp>
#include <opencv2/imgproc.hpp>
#include <iostream>
using namespace cv;
using namespace cv::img_hash;
using namespace std;
void computeHash(cv::Ptr<cv::img_hash::ImgHashBase> algo, char *ref, char *enc)
{
cv::Mat const input = cv::imread(ref);
cv::Mat const target = cv::imread(enc);
cv::Mat inHash; //hash of input image
cv::Mat targetHash; //hash of target image
//comupte hash of input and target
algo->compute(input, inHash);
algo->compute(target, targetHash);
//Compare the similarity of inHash and targetHash
//recommended thresholds are written in the header files
//of every classes
double const mismatch = algo->compare(inHash, targetHash);
std::cout<<mismatch<<std::endl;
}
int main(int argc, char **argv)
{
//disable opencl acceleration may boost up speed of img_hash
//however, in this post I do not disable the optimization of opencl
//cv::ocl::setUseOpenCL(false);
//
if (argc <= 1) {
printf("Usage: reference <image_reference> <encoded_image>\n");
exit(1);
}
std::cout<<"AverageHash:"<<std::endl;
computeHash(img_hash::AverageHash::create(), argv[1], argv[2]);
std::cout<<"PHash:"<<std::endl;
computeHash(img_hash::PHash::create(), argv[1], argv[2]);
std::cout<<"MarrHildrethHash:"<<std::endl;
computeHash(img_hash::MarrHildrethHash::create(), argv[1], argv[2]);
std::cout<<"RadialVarianceHash:"<<std::endl;
computeHash(img_hash::RadialVarianceHash::create(), argv[1], argv[2]);
//BlockMeanHash support mode 0 and mode 1, they associate to
//mode 1 and mode 2 of PHash library
std::cout<<"BlockMeanHash mode 0:"<<std::endl;
computeHash(img_hash::BlockMeanHash::create(0), argv[1], argv[2]);
std::cout<<"BlockMeanHash mode 1:"<<std::endl;
computeHash(img_hash::BlockMeanHash::create(1), argv[1], argv[2]);
std::cout<<"COlorMomentHash:"<<std::endl;
computeHash(img_hash::ColorMomentHash::create(), argv[1], argv[2]);
}