cvMatchShapes解析

 函数 cvMatchShapes 比较两个形状。 三个实现方法全部使用 Hu 矩.
Hu矩具有平移、伸缩和旋转不变形.

那么在匹配中,如下两种方法哪种会更精确些?
1、先进行canny边缘检测 将得到的边缘信息作为输入 再用cvMatchShapes 
2、先进行角点检测 将得到的角点信息作为输入 再用cvMatchShapes  

边缘检测应该会更准确一些. 

# include "cv.h"
# include "highgui.h"
# include <iostream>
using namespace std;

int main()

   IplImage *mode = cvLoadImage("D:\\picture\\jz.jpg", 1);
   IplImage *test = cvLoadImage("D:\\picture\\stuff.jpg", 1);
   IplImage* bw_mode = cvCreateImage(cvGetSize(mode),mode->depth,1);
   IplImage* bw_test = cvCreateImage(cvGetSize(test),mode->depth,1);
   IplImage* canny_mode = cvCreateImage(cvGetSize(mode),mode->depth,1);
   IplImage* canny_test = cvCreateImage(cvGetSize(test),mode->depth,1);

   CvMemStorage *mode_mems=cvCreateMemStorage();
   CvSeq *mode_seqs;
   CvMemStorage *test_mems=cvCreateMemStorage();
   CvSeq *test_seqs;

   cvCvtColor(mode,bw_mode,CV_RGB2GRAY);
   cvCvtColor(test,bw_test,CV_RGB2GRAY);

   //model contours
   cvCanny(bw_mode,canny_mode,50,60);
   cvFindContours( canny_mode, mode_mems,
                  &mode_seqs,sizeof(CvContour),CV_RETR_TREE);

   //test contours
   cvCanny(bw_test,canny_test,50,60);
   cvFindContours( canny_test, test_mems,
                  &test_seqs,sizeof(CvContour),CV_RETR_TREE);

   double matching=cvMatchShapes( test_seqs, mode_seqs, 3);
   cout << matching << endl;
   
   system("pause");
   //释放内存
}

你可能感兴趣的:(opencv,cvMatchShapes)