比较两个图像与opencv的相似性? [英] Compare the similarity of two images with opencv?

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

问题描述

我想检查两个图像相似或不同的opencv。

如果它们是相同的printf(相同);

如果它们不相同printf(不相同);

在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?

推荐答案

这不是那么容易的任务,与一个如果。我推荐的是匹配图像的兴趣点。基本上你可以使用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);

请注意,这是一个非常基本的图像匹配器。如何使它更好,你应该调查它根据你想匹配的图像。另请参阅良好匹配方法,您可以在此找到此处

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天全站免登陆