对cvMatchContourTree的测试代码(还是没找出关系) , 第八章11题
来源:互联网 发布:软件服务行业指标 编辑:程序博客网 时间:2024/06/04 19:58
代码如下:
#include <cv.h>#include <cxcore.h>#include <highgui.h>#include <cvaux.h>#include <iostream>#include <string>#include <strstream>#include <iomanip>#include <cmath>using namespace std;static void imRotate(IplImage *src,IplImage *dst,double angle , CvPoint2D32f center,double scale = 1 );//缩放图像int main(){IplImage *src = cvLoadImage("f:\\images\\test3.bmp",CV_LOAD_IMAGE_GRAYSCALE);IplImage *src_cpy = cvCloneImage(src);CvMemStorage *storage = cvCreateMemStorage();cvThreshold(src,src,50,255,CV_THRESH_BINARY);CvSeq *contour_src = NULL;cvFindContours(src_cpy,storage,&contour_src);//此函数会改变输入图像CvContourTree *tree_src = cvCreateContourTree(contour_src,storage,0);cvReleaseImage(&src_cpy);CvSeq *contour = NULL;CvRNG rng = cvRNG(-1);bool flag = false; //控制scale和angle哪个变量变化while(1){//控制其中一个变化,另一个固定//与原图像比较double scale = 1 , angle = 0;if(flag){scale = cvRandReal(&rng)*1.3;if(scale < 0.5)continue;}elseangle = cvRandReal(&rng)*360;time_t StartTime = clock();IplImage *dst = cvCreateImage(cvSize(src->width,src->height),8,1);imRotate(src,dst,angle,cvPoint2D32f(src->width/2,src->height/2),scale);cvShowImage("dst",dst);cvThreshold(dst,dst,100,255,CV_THRESH_BINARY);cvFindContours(dst,storage,&contour);CvContourTree *tree = cvCreateContourTree(contour,storage,0);double result = cvMatchContourTrees(tree_src,tree,CV_CONTOUR_TREES_MATCH_I1,0);time_t EndTime = clock();cout<<"angle = "<<setprecision(3)<<angle<<" scale = "<<scale<<"\t";cout<<"result = "<<setprecision(3)<<result<<"\ttime = "<<double(EndTime - StartTime)/CLOCKS_PER_SEC<<endl;cvReleaseImage(&dst);cvClearSeq(contour);int key = cvWaitKey();if(key == 27)break;else if(key == 'n' || key == 'N')flag = !flag;}cvReleaseMemStorage(&storage);cvReleaseImage(&src);}void imRotate(IplImage *src, IplImage *dst,double angle , CvPoint2D32f center,double scale){assert(src->width == dst->width && src->height == dst->height &&src->depth == dst->depth &&src->nChannels == dst->nChannels);CvMat *mapMatrix = cvCreateMat(2,3,CV_32FC1);IplImage *tmp = cvCreateImage(cvGetSize(src),src->depth,src->nChannels);cv2DRotationMatrix(center,angle,scale,mapMatrix); //旋转缩放为仿射变换,此处求变换矩阵cvWarpAffine(src,(src->imageData == dst->imageData) ? tmp : dst,mapMatrix); //此函数不能src == dstif(src->imageData == dst->imageData)cvCopyImage(tmp,dst);cvReleaseImage(&tmp);}
使用图像为:
在固定其中一个变量的情况下做匹配,发现得到的值差异很大,不知道这个轮廓树比较得到的结果有什么用处,请各位路过的大侠指教!
试验结果:
从结果中看几乎无关联 , 我又修改了程序
使无旋转时,图像的大小随着scale变化(上面的程序图像大小不变),即用cvResize缩放,仍然是一样的情况 ,看不出关联
- 对cvMatchContourTree的测试代码(还是没找出关系) , 第八章11题
- opencv 对hu不变矩的测试程序cvGetHuMoments,opencv第八章第10题
- javaweb项目的Hibernate映射关系一对多、多对一总结、测试类代码
- 用随机数据测试自己的代码找出错误
- 面向对象对关系的处理没有关系数据库好
- 百度分享代码(收集的,没测试过)
- 先测试还是先代码
- 测试系统是大段还是小端存储的c代码
- 【SSH三大框架】Hibernate基础第八篇:多对多关联关系的操作
- 个人对juc的一些测试代码
- 上午jsp乱码问题我似乎还是没整对
- 找出对oracle测试库的表执行delete的用户
- 找出数组中连续的x个数,使其和最大(《编程珠玑》第八章)
- 没办法还是锁机制的讲解
- thinkphp5的模型关系示例,自己测试的代码
- APPIUM+JAVA实现对安卓APK的自动化测试----第八篇【安装】
- 初学hibernate时,多对多测试代码,中间建了一张关系表。
- 找出一个数组中没重复出现过的数
- 死锁问题
- 只考加法的面试题
- DB---设计数据库的小细节(不断更新)
- 数据库视图作用
- static详解
- 对cvMatchContourTree的测试代码(还是没找出关系) , 第八章11题
- System.in学习
- titles框架介绍
- 贪心算法(Greedy algorithm)
- 一个file实例
- 数据库查询的5种视图以及作用
- 一个文件搜索(使用正则)的例子
- CListCtrl控件使用方法总结
- 正则表达式语法