OpenCV比赛轮廓图 [英] Opencv match contour image

查看:137
本文介绍了OpenCV比赛轮廓图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道什么是比较一组轮廓的最佳策略,实际上是从两张图片中检测到精明边缘得出的边缘,以便知道哪一对更相似.

I'd like to know what would be the best strategy to compare a group of contours, in fact are edges resulting of a canny edges detection, from two pictures, in order to know which pair is more alike.

我有这张图片:

http://i55.tinypic.com/10fe1y8.jpg

我想知道如何计算最合适的其中之一:

And I would like to know how can I calculate which one of these fits best to it:

http://i56.tinypic.com/zmxd13.jpg

(应该是右边的那个)

总有没有比较整个轮廓? 我可以轻松旋转图像,但不知道要使用什么功能来计算右侧的参考图像最合适.

Is there anyway to compare the contours as a whole? I can easily rotate the images but I don't know what functions to use in order to calculate that the reference image on the right is the best fit.

这是我已经使用opencv尝试过的方法:

Here it is what I've already tried using opencv:

matchShapes函数-我使用2个灰度图像尝试了此函数,在每个比较图像中我总是得到相同的结果,并且该值似乎是错误的,因为它是0,0002.

matchShapes function - I tried this function using 2 gray scales images and I always get the same result in every comparison image and the value seems wrong as it is 0,0002.

所以我对matchShapes的了解是什么,但是我不确定这是正确的假设,因为该函数可用于成对的轮廓而不是完整的图像.现在这是一个问题,因为尽管我具有要比较的图像轮廓,但它们有数百个,而且我不知道应该配对"哪些图像.

So what I realized about matchShapes, but I'm not sure it's the correct assumption, is that the function works with pairs of contours and not full images. Now this is a problem because although I have the contours of the images I want to compare, they are hundreds and I don't know which ones should be "paired up".

因此,我还尝试通过 for 迭代将第一张图像的所有轮廓与其他两个图像进行比较,但是我可能正在比较(例如)5的轮廓与两个参考图像而不是两个轮廓.

So I also tried to compare all the contours of the first image against the other two with a for iteration but I might be comparing,for example, the contour of the 5 against the circle contour of the two reference images and not the 2 contour.

还尝试了简单的cv :: compare函数和matchTemplate,但没有成功.

Also tried simple cv::compare function and matchTemplate, none with success.

推荐答案

为此,您有两种选择,具体取决于您要采用的方法的健壮性.

Well, for this you have a couple of options depending on how robust you need your approach to be.

对于这些方法,我假设您提供的图像是您正在使用的图像(即,对象已被分割并且近似相同的比例.此外,您将需要校正旋转(至少在您可以做一些类似的操作,例如每10、30、60或90度迭代比较图像,或者您觉得可以摆脱的任何粗糙程度.

For these methods, I'm assuming your the images you supplied are what you are working with (i.e., the objects are already segmented and approximately the same scale. Also, you will need to correct the rotation (at least in a coarse manner). You might do something like iteratively rotate the comparison image every 10, 30, 60, or 90 degrees, or whatever coarseness you feel you can get away with.

例如,

for(degrees = 10; degrees < 360; degrees += 10)
    coinRot = rotate(compareCoin, degrees)
    // you could also try Cosine Similarity, or even matchedTemplate here.
    metric = SAD(coinRot, targetCoin) 
    if(metric > bestMetric)
        bestMetric = metric
        coinRotation = degrees


  • 绝对差之和(SAD):这将使您可以一次快速比较图像您已经确定了大概的旋转角度.
  • 余弦相似度:通过将图像视为一维矢量,其操作略有不同,并且然后计算两个向量之间的高维角度.匹配越好,角度将越小.

    • Sum of Absolute Differences (SAD): This will allow you to quickly compare the images once you have determined an approximate rotation angle.
    • Cosine Similarity: This operates a bit differently by treating the image as a 1D vector, and then computes the the high-dimensional angle between the two vectors. The better the match the smaller the angle will be.
    • 这些解决方案实施起来会更加复杂,但可能会产生更可靠的分类.

      These solutions will be more complex to implement, but will probably yield more robust classifications.

      • Haussdorf Distance: This answer will give you an introduction on using this method. This solution will probably also need the rotation correction to work properly.
      • Fourier-Mellin Transform: This method is an extension of Phase Correlation, which can extract the rotation, scale, and translation (RST) transform between two images.
      • Feature Detection and Extraction: This method involves detecting "robust" (i.e., scale and/or rotation invariant) features in the image and comparing them against a set of target features with RANSAC, LMedS, or simple least squares. OpenCV has a couple of samples using this technique in matcher_simple.cpp and matching_to_many_images.cpp. NOTE: With this method you will probably not want to binarize the image, so there are more detectable features available.

      这篇关于OpenCV比赛轮廓图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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