作业帮 > 综合 > 作业

我想用opencv提取外矩形,结果提取了画布外轮廓.

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/06/11 21:28:11
我想用opencv提取外矩形,结果提取了画布外轮廓.
cvFindContours(bw,storage,&contour,sizeof(CvContour),CV_RETR_EXTERNAL,CV_CHAIN_APPROX_SIMPLE);
我要提取大圆的外接矩,可是结果提了个画框~
你可以统计外轮廓上点的坐标啊,然后找出左上角和右下角的点,外接矩就出来了.我把我的代码给你贴出来,不明白了再追问我.
CvPoint temp_point;
//初始化角点的坐标,左上角为(0,0),右下角为(height,weight)
int roi_x0 = image->height;
int roi_y0 = image->width;
int roi_x1 = 0;
int roi_y1 = 0;
//遍历轮廓roi_contour上的所有点,并找出左上角和右下角的点
for(int k = 0; k < roi_contour->total; k ++)
\x05{
\x05\x05temp_point = (CvPoint*) cvGetSeqElem(roi_contour,k);
\x05\x05if(temp_point->x < roi_x0)
\x05\x05{
\x05\x05\x05roi_x0 = temp_point->x;
\x05\x05}
\x05\x05if(temp_point->y < roi_y0)
\x05\x05{
\x05\x05\x05roi_y0 = temp_point->y;
\x05\x05}
\x05\x05if(temp_point->x > roi_x1)
\x05\x05{
\x05\x05\x05roi_x1 = temp_point->x;
\x05\x05}
\x05\x05if(temp_point->y > roi_y1)
\x05\x05{
\x05\x05\x05roi_y1 = temp_point->y;
\x05\x05}
\x05}
CvRect roi_rect;//外接矩
\x05roi_rect.x = roi_x0 ;
\x05roi_rect.y = roi_y0 ;
\x05roi_rect.height = (roi_y1 - roi_y0);
\x05roi_rect.width = (roi_x1 - roi_x0);
\x05cout