I succeeded in using cvDrawContour but when I try to use cvMinRectArea2, it only shows one dot. Any ideas? Here’s the source code.
IplImage *src = cvLoadImage("SignImg.jpg",0);
IplImage *dst_img = 0;
IplImage *img = cvCreateImage(cvGetSize(src),8,3);
CvBox2D rect;
CvMemStorage *storage = cvCreateMemStorage ();
CvSeq *contours = 0;
char a[255];
sprintf(&a[0],"%s",openFileDialog1->FileName);
dst_img = cvLoadImage(a,0);
cvFindContours (src, storage, &contours, sizeof(CvContour), CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE ,cvPoint(0,0));
cvCvtColor(dst_img,img,CV_GRAY2BGR);
cvDrawContours (img, contours, CV_RGB(255,0,0), cvScalarAll(255),1,1,8,cvPoint(0,0));
rect=cvMinAreaRect2 (contours,0);
cvEllipseBox(img,rect,cvScalarAll(0),5,8,0);
The right way to use cvDrawContours is shown here:
If it’s not obvious enough, your variable
contoursis an array and you need to iterate over it and draw each element! Else you will be drawing only the first element of the array.