opencv将矩形边界框添加到轮廓
我已经从图像中找到了轮廓,现在我想对轮廓分别应用一个矩形边界框,我还想让计数着色,这是我正在使用的代码opencv将矩形边界框添加到轮廓,opencv,Opencv,我已经从图像中找到了轮廓,现在我想对轮廓分别应用一个矩形边界框,我还想让计数着色,这是我正在使用的代码 int main () { CvSeq*contours=0; CvSeq* canny_contours = 0; CvMemStorage*storage=cvCreateMemStorage(0); CvMemStorage* canny_storage = cvCreateMemStorage(0); IplImage*a=cvLoadIma
int main ()
{
CvSeq*contours=0;
CvSeq* canny_contours = 0;
CvMemStorage*storage=cvCreateMemStorage(0);
CvMemStorage* canny_storage = cvCreateMemStorage(0);
IplImage*a=cvLoadImage("lisc.jpg");
IplImage*b(cvCreateImage(cvGetSize(a),IPL_DEPTH_8U,1));
IplImage*c(cvCreateImage(cvGetSize(b),IPL_DEPTH_8U,1));
IplImage*d(cvCreateImage(cvGetSize(c),IPL_DEPTH_8U,1));
cvCvtColor(a,b,CV_RGB2GRAY);
cvThreshold(b,c,128,255,CV_THRESH_BINARY);
cvCanny(c,d,50,150,3);
cvFindContours(c,storage,&contours,sizeof(CvContour),
CV_RETR_EXTERNAL, CV_CHAIN_CODE);
cvFindContours(d, canny_storage, &canny_contours, sizeof(CvContour),
CV_RETR_EXTERNAL, CV_CHAIN_CODE);
cvDrawContours(c,contours,cvScalar(255,255,255), cvScalarAll(255), 100);
//for( ; canny_contours != 0; canny_contours = canny_contours->h_next )
//{
// CvScalar color = CV_RGB( rand()&200, rand()&200, rand()&200 );
/* replace CV_FILLED with 1 to see the outlines */
cvDrawContours( d, canny_contours, cvScalar(rand()&200,rand()&200,rand()&200),
cvScalarAll(rand()&200),1);
//}
cvNamedWindow("rola",CV_GUI_NORMAL);
cvNamedWindow("meaow0",CV_GUI_NORMAL);
cvShowImage("rola",c);
cvShowImage("meaow0",d);
cvWaitKey(0);
cvReleaseImage(&c);
cvReleaseImage(&d);
}
我不熟悉C风格的API。但也许你可以使用下面的函数
Rect r = cvBoundingRect(points,0);
在C++中,点是“STD::向量”。
我找不到合适的syntex,无法在我的代码中实现它们