找轮廓、轮廓的最小外接矩形

找轮廓

	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

猜你喜欢

转载自blog.csdn.net/qq_30263737/article/details/80179056