double cvMatchShapes(
const void* object1,
const void* object2,
int method,
double parameter = 0
);
第一个参数是待匹配的物体1,第二个是待匹配的物体2
第三个参数method可以有CV_CONTOURS_MATCH_I1,CV_CONTOURS_MATCH_I2,CV_CONTOURS_MATCH_I3
三种输入,这其实就是三种不同的判定物体相似的方法,匹配的返回值也是不一样的其返回值分别通过下面的公式计算得出
# include "cv.h"
# include "highgui.h"
# include <iostream>
using namespace std;
int main()
{
}
{
IplImage *mode = cvLoadImage("D:\\lena.jpg", 1);
IplImage *test = cvLoadImage("D:\\test3.bmp", 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( bw_mode, mode_mems,
&mode_seqs,sizeof(CvContour),CV_RETR_TREE);
//test contours
//cvCanny(bw_test,canny_test,50,60);
cvFindContours( bw_test, test_mems,
&test_seqs,sizeof(CvContour),CV_RETR_TREE);
double matching=cvMatchShapes( test_seqs, mode_seqs, 3);
printf("%f",matching);
cvReleaseImage( &mode ); //ÊÍ·ÅͼÏñ
cvReleaseImage( &test );
cvReleaseImage( &bw_mode ); //ÊÍ·ÅͼÏñ
cvReleaseImage( &bw_test );
cvReleaseImage( &canny_mode ); //ÊÍ·ÅͼÏñ
cvReleaseImage( &canny_test );
//ÊÍ·ÅÄÚ´æ
return 1;
}