opencv 对获得的Canny 边缘操作

狂暴果冻 2013-12-26 10:53:19
在opencv2 中用findcontours()函数获取图像中的边缘轮廓,进而可以获取轮廓的lenghth等信息,但是我现在要实现的是对用Canny 边缘检测结果中的边缘信息进行删减,在canny边缘的基础上进行findcontours 操作不能得到所想要的结果,请教该使用什么样的操作可以实现对canny边缘的删减?
...全文
300 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
qiukaijia 2013-12-26
  • 打赏
  • 举报
回复
调一下大阈值和小阈值,可以得到相应的结果
赵4老师 2013-12-26
  • 打赏
  • 举报
回复
        // find contours and store them all as a list
        findContours(gray1, contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);

        vector<Point> approx;

        // test each contour
        for (size_t i = 0; i < contours.size(); i++ ) {
            // approximate contour with accuracy proportional
            // to the contour perimeter
            approxPolyDP(Mat(contours[i]), approx, arcLength(Mat(contours[i]), true)*0.02, true);//0.02为将毛边拉直的系数,如果对毛边正方形漏检,可试试调大

            // square contours should have 4 vertices after approximation
            // relatively large area (to filter out noisy contours)
            // and be convex.
            // Note: absolute value of an area is used because
            // area may be positive or negative - in accordance with the
            // contour orientation
            if (approx.size() == 4 && isContourConvex(Mat(approx))) {
                double area;
                area=fabs(contourArea(Mat(approx)));
                if (4000.0<area && area<30000.0) {//当正方形面积在此范围内……,如果有因面积过大或过小漏检正方形问题,调整此范围。
//                  printf("area=%lg\n",area);
                }
            }
        }

64,662

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧