我用C++工作和OpenCV如何获得的轮廓角OpenCV中
我检测图像中的轮廓大,因为我有它的黑色区域。
在这种情况下,该区域只是水平的,但它可以在任何地方。
Mat resultGray;
cvtColor(result,resultGray, COLOR_BGR2GRAY);
medianBlur(resultGray,resultGray,3);
Mat resultTh;
Mat canny_output;
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
Canny(resultGray, canny_output, 100, 100*2, 3);
findContours(canny_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
Vector<Point> best= contours[0];
int max_area = -1;
for(int i = 0; i < contours.size(); i++) {
Scalar color = Scalar(0, 0, 0);
if(contourArea(contours[i])> max_area)
{
max_area=contourArea(contours[i]);
best=contours[i];
}
}
Mat approxCurve;
approxPolyDP(Mat(best),approxCurve,0.01*arcLength(Mat(best),true),true);
这样,我有大的轮廓和近似值(以approxCurve)。现在,我想获得这个近似的角点,并获得这个轮廓内的图像,但我不知道我该怎么做。
我正在使用这个How to remove black part from the image? 但是最后一部分我不会非常好地描述。
任何人都知道我该如何获得角落?这是另一种更简单的方式吗?
感谢您的时间,