您的位置:首页 > 运维架构

opencv 查找并绘制轮廓

2017-11-15 20:48 791 查看
#include<opencv2/opencv.hpp>

#include<opencv2/core/core.hpp>

#include<opencv2/imgproc/imgproc.hpp>

#include<iostream>

using namespace cv;

using namespace std;

 

int main()

{
Mat srcImage = imread("1.jpg",0);
imshow("yuantu",srcImage);
Mat dstImage = Mat::zeros(srcImage.rows,srcImage.cols,CV_8SC3);
srcImage = srcImage > 119;
imshow("fazhitu",srcImage);
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;

findContours(srcImage,contours,hierarchy,RETR_CCOMP,CHAIN_APPROX_NONE);
int index = 0;
for(; index >= 0;index = hierarchy[index][0])
{
//drawChessboardCorners(InputOutputArray image,Size patternSize,InputArray corners,bool patternWasFound)
Scalar color(rand()&255,rand()&255,rand()&255);
drawContours(dstImage,contours,index,color,FILLED,8,hierarchy);
}
imshow("lunkuotu",srcImage);
waitKey(0);
return 0;
}

运行图如下

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  opencv