#include <iostream>
#include <string>
#include <sstream>
#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
using namespace std;
int main()
{
IplImage *srcColor = cvLoadImage("E:\\study_opencv_video\\lesson15_3\\2.jpg", 1);
IplImage *src = cvCreateImage(cvGetSize(srcColor), 8, 1);
cvCvtColor(srcColor, src, CV_BGR2GRAY);
if(!src)
{
cout << "No Image Load" << endl;
}
int i;
stringstream ss;
string path;
string str;
IplImage *dst = NULL, *dstColor;
char c[256];
double result, maxResult= 1000 * 256 *256;
IplImage *resultMap = NULL;
for (i = 3; i < 12; i ++)
{
path = "E:\\study_opencv_video\\lesson15_3\\";
ss.clear();
ss << i;
ss >> str;
str += ".jpg";
path += str;
ss.clear();
ss << path;
ss >> c;
dstColor = cvLoadImage(c,1); //读取图片
dst = cvCreateImage(cvGetSize(dstColor), 8, 1);
cvCvtColor(dstColor, dst, CV_BGR2GRAY);
result = cvMatchShapes(src, dst, 1);
if(maxResult > result) //求最大相似
{
resultMap = cvCreateImage(cvGetSize(dstColor), 8, 3);
maxResult = result;
cvCopy(dstColor, resultMap);
}
}
cvNamedWindow("srcColor", 0);
cvNamedWindow("resultMap",0);
cvShowImage("resultMap", resultMap);
cvShowImage("srcColor", srcColor);
cvWaitKey(0);
cvReleaseImage(&src);
cvReleaseImage(&srcColor);
cvReleaseImage(&dst);
cvReleaseImage(&dstColor);
cvReleaseImage(&resultMap);
cvDestroyWindow("srcColor");
cvDestroyWindow("resultMap");
return 0;
}
Hu矩阵计算两个轮廓的相似度
最新推荐文章于 2024-06-04 20:29:34 发布