java sift 图片相似度,简单快速的图像相似性比较方法

我最近也面临同样的问题,为了解决这个问题(简单快速的算法比较两个图像),我贡献了

img_hash module

要打开“控制”,您可以从

this link

.

img_哈希模块提供六种图像哈希算法,非常容易使用。

代码示例

e8Hvu.png

起源Lena

KVGLM.png

模糊莉娜

bCvaw.png

调整Lena的大小

GeYPT.png

移动Lena

#include

#include

#include

#include

#include

#include

void compute(cv::Ptr<:img_hash::imghashbase> algo)

{

auto input = cv::imread("lena.png");

cv::Mat similar_img;

//detect similiar image after blur attack

cv::GaussianBlur(input, similar_img, {7,7}, 2, 2);

cv::imwrite("lena_blur.png", similar_img);

cv::Mat hash_input, hash_similar;

algo->compute(input, hash_input);

algo->compute(similar_img, hash_similar);

std::cout<

algo->compare(hash_input, hash_similar)<<:endl>

//detect similar image after shift attack

similar_img.setTo(0);

input(cv::Rect(0,10, input.cols,input.rows-10)).

copyTo(similar_img(cv::Rect(0,0,input.cols,input.rows-10)));

cv::imwrite("lena_shift.png", similar_img);

algo->compute(similar_img, hash_similar);

std::cout<

algo->compare(hash_input, hash_similar)<<:endl>

//detect similar image after resize

cv::resize(input, similar_img, {120, 40});

cv::imwrite("lena_resize.png", similar_img);

algo->compute(similar_img, hash_similar);

std::cout<

algo->compare(hash_input, hash_similar)<<:endl>

}

int main()

{

using namespace cv::img_hash;

//disable opencl acceleration may(or may not) boost up speed of img_hash

cv::ocl::setUseOpenCL(false);

//if the value after compare <= 8, that means the images

//very similar to each other

compute(ColorMomentHash::create());

//there are other algorithms you can try out

//every algorithms have their pros and cons

compute(AverageHash::create());

compute(PHash::create());

compute(MarrHildrethHash::create());

compute(RadialVarianceHash::create());

//BlockMeanHash support mode 0 and mode 1, they associate to

//mode 1 and mode 2 of PHash library

compute(BlockMeanHash::create(0));

compute(BlockMeanHash::create(1));

}

在这种情况下,colormomenthash给我们最好的结果

高斯模糊攻击:0.567521

轮班攻击:0.229728

调整攻击大小:0.229358

每种算法的优缺点

m2Sd9.jpg

img_哈希的性能也很好

与Phash库的速度比较(UKbench的100张图像)

W8uJS.jpg

Pbmbd.jpg

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值