来者有分!关于cvApproxPoly()和cvFindDominantPoints()的用法!
本帖最后由 crystal8700 于 2010-08-09 10:03:33 编辑 问题一:关于cvApproxPoly()的用法
#include"stdafx.h"
#include"cv.h"
#include"highgui.h"
void main()
{
IplImage *src=cvLoadImage("D:\\image\\hand2.jpg",0);
IplImage *tmp=cvCreateImage(cvGetSize(src),src->depth,1);
IplImage *dst=cvCreateImage(cvGetSize(src),src->depth,3);
CvMemStorage *stor=cvCreateMemStorage(0);
CvMemStorage *mstor=cvCreateMemStorage(0);
CvMemStorage *mstor2=cvCreateMemStorage(0);
CvSeq *cont=NULL,*mcont=NULL,*mcont2=NULL;
cvThreshold(src,tmp,50,255,CV_THRESH_BINARY);
cvFindContours(tmp,stor,&cont,sizeof(CvContour),CV_RETR_LIST,CV_CHAIN_APPROX_SIMPLE,cvPoint(0,0));
cvCvtColor(tmp,dst,CV_GRAY2BGR);
if(cont)
{
//cvDrawContours(dst,cont,CV_RGB(0,255,0),CV_RGB(0,0,255),1,2,8,cvPoint(0,0));
mcont=cvApproxPoly(cont,sizeof(CvContour),mstor,CV_POLY_APPROX_DP,cvContourPerimeter(cont)*0.02,0);
cvDrawContours(dst,mcont,CV_RGB(255,0,0),CV_RGB(0,0,255),1,2,8,cvPoint(0,0));
}
cvNamedWindow("approxPoly",0);
cvShowImage("approxPoly",dst);
cvWaitKey(0);
cvReleaseImage(&src);
cvReleaseImage(&tmp);
cvReleaseImage(&dst);
cvReleaseMemStorage(&stor);
cvReleaseMemStorage(&mstor);
cvReleaseMemStorage(&mstor2);
cvDestroyAllWindows();
}