本文实例为大家分享了opencv提取轮廓大于某个阈值的图像,供大家参考,具体内容如下
#include "stdafx.h" #include "cv.h" #include "highgui.h" #include "stdio.h" #include"core/core.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2/core/core.hpp" #include "opencv2/imgproc/imgproc.hpp" #include <iostream> using namespace cv; using namespace std; int main(int argc, char** argv) { const char* inputImage = "d:/3.jpg"; Mat img; int threshval =100; img = imread(inputImage,0); if (img.empty()) { cout << "Could not read input image file: " << inputImage << endl; return -1; } img = img >110; namedWindow("Img", 1); imshow("Img", img); vector<vector<Point> > contours; vector<Vec4i>hierarchy; vector<Point> contour; Mat dst = Mat::zeros(img.rows, img.cols, CV_8UC3); findContours(img, contours,hierarchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE); int m=contours.size();//得到轮廓的数量 int n=0; for (int i =0;i<m;++i) { n=contours[i].size(); for (int j =0;j<n;++j) { contour.push_back(contours[i][j]);//读取每个轮廓的点 } double area = contourArea(contour); //取得轮廓面积 if (area>10)//只画出轮廓大于10的点 { Scalar color( (rand()&255), (rand()&255), (rand()&255) ); drawContours( dst, contours, i, color, 1, 8, hierarchy ); } contour.clear(); } namedWindow("src", 1); imshow( "src", dst ); waitKey(); return 0; }
另外有需要云服务器可以了解下创新互联建站www.cdcxhl.com,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
本文标题:opencv提取轮廓大于某个阈值的图像-创新互联
文章URL:https://www.cdcxhl.com/article38/csedpp.html
成都网站建设公司_创新互联,为您提供微信小程序、网站建设、面包屑导航、网站内链、网站导航、外贸网站建设
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联