全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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年河南省义马市高二化学下册期末考试模拟试卷含完整答案【必刷】
- 2026年贵州省清镇市高二化学下册期末考试模拟测试卷完美版附答案
- 2026年青海省格尔木市高二化学下册期末考试模拟检测卷附答案【能力提升】
- 2026年河北省霸州市高二化学下册期末考试模拟测试卷附参考答案【预热题】
- 2026年山东省禹城市高二化学下册期末考试模拟试卷(典优)附答案
- 2026年黑龙江省尚志市高二化学下册期末考试模拟检测卷及答案1套
- 2026年江苏省太仓市高二化学下册期末考试模拟测试卷附完整答案【典优】
- 2026年浙江省平湖市高二化学下册期末考试模拟考试卷【模拟题】附答案
- 2026年湖北省石首市高二化学下册期末考试模拟卷附参考答案(综合卷)
- 班主任辞职申请书
- 97G329-8建筑抗震结构详图(钢筋砼柱单层厂房)图集
- 省级行业产教融合共同体申报书、申报书、参与建设证明
- 危险源辨识新表
- TD/T 1010-2015 土地利用动态遥感监测规程(正式版)
- 静配中心PIVAS细胞毒性药物配置的操作方法
- 脓毒症及相关并发症的护理
- DB21-T 2819-2017岩土工程勘察报告编制规范
- 《铁道车辆制动装置及制动新技术》 课件 7.2货车脱轨自动制动装置的检修工艺流程
- WHO儿童生长发育标准
- 保险学(张洪涛第五版)习题库及答案
评论
0/150
提交评论