使用感知哈希方法,进行缩略图比较,来判断图像的相似度
先把目录下的所有图片都读取出来,再进行判断
优点:速度快
缺点:获取所有图像的指纹需要较多内存和时间来进行处理
#include <iostream>
#include <unistd.h>
#include <dirent.h>
#include <sys/stat.h>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
using namespace std;
using namespace cv;
//使用感知哈希算法进行图片去重
//构建一个结构体,用于存储对应名称和要比较的内容
typedef struct MatStruct{
string name;
unsigned char buf[64];
MatStruct(){
name = "";
memset(buf, 0, 64);
}
MatStruct(const struct MatStruct &ms){
name = ms.name;
memset(buf, 0, 64);
memcpy(buf, ms.buf, 64);
}
//重载比较函数
bool operator<(const struct MatStruct &ms)const {
return name < ms.name;
}
}MatStruct;
int getdirimages(string p