• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

用opencv比较两张图片的相似度?

用户头像
it1352
帮助2

问题说明

我想用 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?

正确答案

#1

不是那么容易的事,一个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.

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhecejhc
系列文章
更多 icon
同类精品
更多 icon
继续加载