用opencv比较两张图片的相似度? [英] Compare the similarity of two images with opencv?

查看:129
本文介绍了用opencv比较两张图片的相似度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用 opencv 检查两个图像是否相似或不同.

如果它们相同 printf("same");

如果它们不相同 printf("not same");

在opencv中有什么方法或方法吗?

I want to check two images are similar or different with opencv.

if they are same printf("same");

if they are not same printf("not same");

is there any method or way for that in opencv?

推荐答案

不是那么容易的事,一个if也不可能做到.我推荐的是匹配图像的兴趣点.基本上,您可以使用 opencv 库来识别图像上的兴趣点并执行它们的匹配.如果匹配的百分比足够高,则可以得出图像相同的结论.在大多数情况下,此百分比取决于您要匹配的图像类型.这意味着您需要调整接受百分比的值.

It is not so easy task, and it is impossible to do with one if. What I recommend is to match image's interest points. Basically you can use opencv library to identify interest points on images and perform the match of them. If the percentage of the match is high enough, you can conclude that images are the same. This percentage in most cases depends of kind of images which you want to match. It means that you need to adjust the value of the acceptance percentage.

要执行指纹匹配,您可以使用 ORB、FREAK、BRISK、SURF 算法.但我建议你使用 ORB.您可以在此处了解更多信息.

To perform fingerprint matching you can use ORB,FREAK,BRISK,SURF algorithms. But I recommend you to use ORB. You can read more about this here.

以下是一些使用 OpenCV for Java 的技巧:

Here is some tips how you can do it with OpenCV for Java:

//Load images to compare
Mat img1 = Highgui.imread(filename1, Highgui.CV_LOAD_IMAGE_GRAYSCALE);
Mat img2 = Highgui.imread(filename1, Highgui.CV_LOAD_IMAGE_GRAYSCALE);

MatOfKeyPoint keypoints1 = new MatOfKeyPoint();
MatOfKeyPoint keypoints2 = new MatOfKeyPoint();
Mat descriptors1 = new Mat();
Mat descriptors2 = new Mat();

//Definition of ORB keypoint detector and descriptor extractors
FeatureDetector detector = FeatureDetector.create(FeatureDetector.ORB); 
DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.ORB);

//Detect keypoints
detector.detect(img1, keypoints1);
detector.detect(img2, keypoints2);  
//Extract descriptors
extractor.compute(img1, keypoints1, descriptors1);
extractor.compute(img2, keypoints2, descriptors2);

//Definition of descriptor matcher
DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING);

//Match points of two images
MatOfDMatch matches = new MatOfDMatch();
matcher.match(descriptors1,descriptors2 ,matches);

请注意,它是一个非常基本的图像匹配器.如何让它变得更好你应该根据你想要匹配的图像来调查它.还可以查看 Good Matches 方法,您可以在此处找到该方法.

Note that it is a quite basic image matcher. How to make it better you should investigate it according to images that you want to match. Also take a look to Good Matches method, which you can find here.

这篇关于用opencv比较两张图片的相似度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆