寻找最小矩形边框--OpenCv
作者:互联网
好久没有写博客了
今天写一下比较常用的寻找矩形边框
////////////////////////////寻找最矩形边框////////////////////////////////////////////////////////// vector<vector<Point>>contours; vector<Vec4i>hierarchy; findContours(g_grayImage, contours, hierarchy, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE); RotatedRect box; double area = 0; for (int i = 0; i < contours.size(); i++) { if (contourArea(contours[i]) > area) { box = minAreaRect(contours[i]); area = contourArea(contours[i]); } } Point2f vertex[4]; box.points(vertex); for (int i = 0; i < 4; i++) { line(g_grayImage, vertex[i], vertex[(i + 1) % 4], Scalar(100, 200, 211), 2, LINE_AA); } imshow("框选", g_grayImage);
标签:box,area,vertex,边框,OpenCv,contours,矩形,grayImage 来源: https://www.cnblogs.com/Loving-Q/p/12061490.html