OpenCV findContours函数时的小发现
来源:互联网 发布:软件行业增值税税率 编辑:程序博客网 时间:2024/06/05 15:50
在应用opencv中findContours()函数与drawContours()函数进行滤波时,将检测到的面积小于某个值的轮廓使用drawContours()函数涂成黑色,此时在显示的图片上看不到该轮廓,但是此时的轮廓并没有在vector<vector<Point> > contours容器中删除。
实验过程:
原图为
经过一系列处理之后,利用下列代码将小于40的轮廓滤除,并将大于40的轮廓填充为白色
vector<vector<Point>> twocontours; vector<Vec4i> twohierarchy; findContours(result4,twocontours,twohierarchy,CV_RETR_TREE,CV_CHAIN_APPROX_SIMPLE); for(inti = 0; i < (int)twocontours.size();i++) { if (int(twocontours.at(i).size())<= 40) { drawContours(result4, twocontours, i, Scalar(0), CV_FILLED); } else { drawContours(result4,twocontours, i, Scalar(255), CV_FILLED); } }效果为:
此时将代码修改,在填充之后重新对counter进行填充
vector<vector<Point> > twocontours; vector<Vec4i> twohierarchy; findContours(result4,twocontours,twohierarchy,CV_RETR_TREE,CV_CHAIN_APPROX_SIMPLE); for(inti = 0; i < (int)twocontours.size();i++) { if (int(twocontours.at(i).size())<= 40) { drawContours(result4, twocontours, i, Scalar(0), CV_FILLED); } else { drawContours(result4, twocontours, i, Scalar(255), CV_FILLED); } } for(inti = 0; i < (int)twocontours.size();i++) { drawContours(result4, twocontours, i,Scalar(255), CV_FILLED); }
效果是,之前过滤掉的面积小于40的轮廓被重新填充回来,说明容器counter本身不会受到drawContours函数填充的影响。
2 0
- OpenCV findContours函数时的小发现
- OpenCV中findContours函数的使用
- opencv.cv2.findContours()函数
- OpenCV - findContours函数使用
- OpenCV之findContours函数解读
- OpenCV之findContours函数解读
- opencv里findcontours函数中hierarchy的意义
- OpenCV中用findContours函数出现的问题和解决方法
- 使用OpenCV的函数findContours提取轮廓并绘制轮廓
- Opencv--findContours()的使用陷阱
- opencv中的findContours的使用
- [转]opencv轮廓提取(findcontours函数详解)
- Opencv笔记——findContours函数
- 实现OPENCV之findcontours函数(一)
- OpenCV findContours函数边缘近似方法
- Opencv笔记——findContours函数
- 25 python-opencv cv2.findcontours函数
- OpenCV之findContours函数及参数讲解
- Java进阶之Annotation(注解)——Annotation(注解)概念
- 成功的背后
- 牛客网刷题之连续子数组的最大和
- 学习随笔
- c语言 格式转换符 %f %e %g 有什么区别
- OpenCV findContours函数时的小发现
- 如何用Azure Web App Services接入微信公众号
- Latex插入编号
- JSPatch库, 一个Apple官方支持的实现在线更新iOS应用的库
- 二进制数转换成十进制数(栈来实现)
- House Robber(leetcode)
- webView访问HTTPS
- JSONP原理优缺点(只能GET不支持POST)
- 安卓踩过的坑