全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
opencv轮廓提取与轮廓拟合 #include #include #include #include #include using namespace std; using namespace cv; int main() / Read input binary image Mat image= imread(“./binaryGroup.bmp“,0); if (!image.data) return 0; namedWindow(“Binary Image“); imshow(“Binary Image“,image); / Get the contours of the connected components vector contours; /findContours的输入是二值图像 findContours(image, contours, / a vector of contours CV_RETR_EXTERNAL, / retrieve the external contours CV_CHAIN_APPROX_NONE); / retrieve all pixels of each contours / Print contours length轮廓的个数 cout :const_iterator itContours= contours.begin(); for ( ; itContours!=contours.end(); +itContours) cout size() :const_iterator itc= contours.begin(); while (itc!=contours.end() if (itc-size() size() cmax) itc= contours.erase(itc); else +itc; / draw contours on the original image Mat original= imread(“./group.bmp“); drawContours(original,contours, -1, / draw all contours Scalar(255,255,255), / in white 2); / with a thickness of 2 namedWindow(“Contours on Animals“); imshow(“Contours on Animals“,original); / Lets now draw black contours on white image /result.setTo(Scalar(0); /If the third parameter of this function is a negative value, then all contours are drawn. /Otherwise, it is possible to specify the index of the contour to be drawn drawContours(result,contours, -1, / draw all contours Scalar(255), / in black 1); / with a thickness of 1 image= imread(“./binaryGroup.bmp“,1); / testing the bounding box Rect r0= boundingRect(Mat(contours0);/boundingRect获取这 个外接矩形 rectangle(result,r0,Scalar(255,255,255),2); / testing the enclosing circle float radius; Point2f center; minEnclosingCircle(Mat(contours1),center,radius);/对轮廓进 行多变形逼近 circle(result,Point(center),static_cast(radius),Scalar(2 55),2); RotatedRect rrect= fitEllipse(Mat(contours2); ellipse(result,rrect,Scalar(255),2); /testing the approximate polygon vector poly; approxPolyDP(Mat(contours2),poly,5,true); cout :const_iterator itp= poly.begin(); while (itp!=(poly.end()-1) line(result,*itp,*(itp+1),Scalar(255),2); +itp; / last point linked to first point line(result,*(poly.begin(),*(poly.end()-1),Scalar(20),2); / testing the convex hull vector hull; convexHull(Mat(contours3),hull); / Iterate over each segment and draw it vector:const_iterator it= hull.begin(); while (it!=(hull.end()-1) line(result,*it,*(it+1),Scalar(255),2); +it; / last point linked to first point line(result,*(hull.begin(),*(hull.end()-1),Scalar(255),2); / testing the moments /iterate over all contours itc= contours.begin(); while (itc!=contours.end() / compute all moments Moments mom= moments(Mat(*itc+); / draw mass center circle(result, / position of mass center converted to integer Point(mom.m10/mom.m00,mom.m01/mom.m00), 2,Scalar(255),2); / draw black dot namedWindow(“Some Shape descriptors“); imshow(“Some Shape descriptors“,result); / New call to findContours but with CV_RETR_LIST flag image= imread(“./binaryGroup.bmp“,0); / Get the contours of the connected components findContours(image, contours, / a vector of contours CV_RETR_LIST, / retrieve the external and internal contours CV_CHAIN_APPROX_NONE); / retrieve all pixels of each contours / draw black contours on white image result.setTo(Scalar(0); drawContours(result,contours, -1, / draw all contours Scalar(255), / in black 2); / with
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 上消化道出血急救护理标准化流程与止血干预实践指南
- (新教材)2026年沪科版八年级下册数学 18.2 勾股定理的逆定理 课件
- 风疹全程护理管理
- 2025年办公楼智能安防监控安装合同协议
- 货物装卸作业安全操作规程
- 传染性单核细胞增多症课件
- 基于多模态数据的信用评分模型
- 2025年智能传感器技术发展报告
- 土壤酸化治理
- 2026 年中职局域网管理(局域网配置)试题及答案
- 2025年沈阳华晨专用车有限公司公开招聘笔试历年参考题库附带答案详解
- 2026(苏教版)数学五上期末复习大全(知识梳理+易错题+压轴题+模拟卷)
- 2024广东广州市海珠区琶洲街道招聘雇员(协管员)5人 备考题库带答案解析
- 蓄电池安全管理课件
- 建筑业项目经理目标达成度考核表
- 2025广东肇庆四会市建筑安装工程有限公司招聘工作人员考试参考题库带答案解析
- 第五单元国乐飘香(一)《二泉映月》课件人音版(简谱)初中音乐八年级上册
- 简约物业交接班管理制度
- 收购摩托驾校协议书
- 2025年浙江省中考数学试卷(含答案)
- 汽车行业可信数据空间方案
评论
0/150
提交评论