找轮廓
vector<vector<Point>> contours; vector<Vec4i> hierarchy; //只提取最外层的轮廓 findContours(thresh_Img, contours, hierarchy, RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
轮廓个数
contours.size()
画轮廓
Mat contours_Img= Mat::zeros(thresh_Img.size(), CV_8U);; drawContours(contours_Img, contours, -1, Scalar(255), CV_FILLED);
用最小外接矩形计算长度、宽度、长宽比
RotatedRect boundingBox = minAreaRect(defectsContours[i]); data.length = boundingBox.size.width * fPixelSizeRatio; data.width = boundingBox.size.height * fPixelSizeRatio;
轮廓中心及角度
boundingBox.center.x boundingBox.center.y boundingBox.angle