从OpenCV matchShapes()解释数字 [英] Explain numbers from OpenCV matchShapes()

查看:784
本文介绍了从OpenCV matchShapes()解释数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,其中我使用OpenCV的matchShapes()比较两个图像.

I am developing an app where I compare two images using matchShapes() of OpenCV.

我在Objective-C代码中实现了下面的方法

I implemented the method in Objective-C code is below

- (void) someMethod:(UIImage *)image :(UIImage *)temp {

RNG rng(12345);

cv::Mat src_base, hsv_base;
cv::Mat src_test1, hsv_test1;

src_base = [self cvMatWithImage:image];
src_test1 = [self cvMatWithImage:temp];

int thresh=150;
double ans=0, result=0;

Mat imageresult1, imageresult2;

cv::cvtColor(src_base, hsv_base, cv::COLOR_BGR2HSV);
cv::cvtColor(src_test1, hsv_test1, cv::COLOR_BGR2HSV);

std::vector<std::vector<cv::Point>>contours1, contours2;
std::vector<Vec4i>hierarchy1, hierarchy2;

Canny(hsv_base, imageresult1, thresh, thresh*2);
Canny(hsv_test1, imageresult2, thresh, thresh*2);

findContours(imageresult1,contours1,hierarchy1,CV_RETR_TREE,CV_CHAIN_APPROX_SIMPLE,cvPoint(0,0));
for(int i=0;i<contours1.size();i++)
{
    Scalar color=Scalar(rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255));
    drawContours(imageresult1,contours1,i,color,1,8,hierarchy1,0,cv::Point());
}

findContours(imageresult2,contours2,hierarchy2,CV_RETR_TREE,CV_CHAIN_APPROX_SIMPLE,cvPoint(0,0));
for(int i=0;i<contours2.size();i++)
{
    Scalar color=Scalar(rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255));
    drawContours(imageresult2,contours2,i,color,1,8,hierarchy2,0,cv::Point());
}

for(int i=0;i<contours1.size();i++)
{
    ans = matchShapes(contours1[i],contours2[i],CV_CONTOURS_MATCH_I1,0);
    std::cout<<ans<<" ";
    getchar();
}

}

我得到了这些结果,但不知道这些数字到底是什么意思:0 0 0.81946 0.816337 0.622353 0.634221 0

推荐答案

this blogpost I think should give a lot more insight into how matchShapes works.

您显然已经知道输入参数是什么,但是对于发现以下内容的任何人:

You obviously already know what the input parameters are but for anyone finding this that doesn't:

double matchShapes(InputArray contour1, InputArray contour2, int method, double parameter)

输出是一个度量标准,其中:

The output is a metric where:

结果越低,匹配越好.它是基于hu-moment值计算的.文档中介绍了不同的测量方法.

The lower the result, the better match it is. It is calculated based on the hu-moment values. Different measurement methods are explained in the docs.

提到的博客文章的发现如下:(max = 1,min = 0)

The findings on the blogpost mentioned are as follows: ( max = 1 , min = 0)

我得到以下结果:

I got following results:

    Matching Image A with itself = 0.0
    Matching Image A with Image B = 0.001946
    Matching Image A with Image C = 0.326911

看,即使图像旋转对这次比较也没有太大影响.

See, even image rotation doesn’t affect much on this comparison.

这基本上表明了您的结果:

This basically shows that for your results:

  1. 前两个很棒,您的比赛完全是0分
  2. 后两个(0.81946 0.816337)完全不兼容
  3. 第三个是可以的,不兼容程度约为62%
  4. 最后一个是完全比赛.

如果我的计算机视觉学习告诉我,除非您100%使用相同的图像,否则任何事物总是对完全匹配持怀疑态度.

If my computer vision learnings have taught me anything is always be sceptical of a complete match unless you are 100% using the same images.

Edit1:我认为它在旋转方面也可能是不变的,因此在您的情况下,您可能具有三个非常相似的绘制线,它们已经以相同的方式(即水平)旋转并进行了比较

I think it might also be rotationally invarient so in your case you might have three very similar drawn lines that have been rotated to the same way (i.e. horizontal) and compared

这篇关于从OpenCV matchShapes()解释数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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