Hai
1 IplImage* printrect(IplImage *contourim) 2 { 3 4 IplImage *rectim=cvCreateImage(cvGetSize(contourim), IPL_DEPTH_8U, 3); 5 int flag=1; 6 vector<Point> points; 7 for(;contourSeq!=NULL;contourSeq=contourSeq->h_next) 8 { 9 10 11 for(int i=0;i<contourSeq->total;i++) 12 { 13 CvPoint p; 14 CvPoint* p1=(CvPoint*)cvGetSeqElem(contourSeq,i); 15 p.x=p1->x; 16 p.y=p1->y; 17 points.push_back(p); 18 19 } 20 printf("No.%d contoured has pushed back\n",flag); 21 flag++; 22 CvRect rect = boundingRect(points); 23 CvPoint pt1,pt2; 24 pt1.x=rect.x; 25 pt1.y=rect.y; 26 pt2.x=rect.x+rect.width; 27 pt2.y=rect.y+rect.height; 28 cvRectangle(contourim,pt1,pt2,CV_RGB(0,0,255)); 29 points.swap(vector<Point>());//每次使用完必须清空容器 30 } 31 rectim=contourim; 32 return rectim; 33 34 35 }