/// 多边形逼近轮廓 + 获取矩形边界框
vector<Point> contours_poly;
Rect boundRect;
//approxPolyDP( Mat(contours[max_channel_Id][max_channel_contour_Id]), contours_poly, 3, true );
boundRect = boundingRect( Mat(contours[max_channel_Id][max_channel_contour_Id]));
vector<Point> boundRectPoint;
boundRectPoint.push_back(Point2f((float)boundRect.x , (float)boundRect.y));
boundRectPoint.push_back(Point2f((float)(boundRect.x + boundRect.width) , (float)boundRect.y));
boundRectPoint.push_back(Point2f((float)boundRect.x , (float)(boundRect.y+boundRect.height)));
boundRectPoint.push_back(Point2f((float)(boundRect.x+boundRect.width) , (float)(boundRect.y+boundRect.height)));
//轮廓长度
double boundcontoursLength=arcLength(contours[max_channel_Id][max_channel_contour_Id],true );
double boundRectLength=arcLength(boundRectPoint,true );
double boundlengthRatio=boundcontoursLength/boundRectLength;
cout<<"boundlengthRatio: "<<boundlengthRatio<<endl;
多边形轮廓
最新推荐文章于 2024-04-27 16:10:43 发布