首页 > 其他 > 详细

寻找最小矩形边框--OpenCv

时间:2019-12-18 19:37:50      阅读:115      评论:0      收藏:0      [点我收藏+]

好久没有写博客了 

今天写一下比较常用的寻找矩形边框

        ////////////////////////////寻找最矩形边框//////////////////////////////////////////////////////////
        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);

寻找最小矩形边框--OpenCv

原文:https://www.cnblogs.com/Loving-Q/p/12061490.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!