opencv27-轮廓发现

#include<opencv2\opencv.hpp>
#include<iostream>
#include<math.h>
using namespace cv;
using namespace std;
Mat src, temp, dst;
int threshold_value = 100;
int threshold_max = 255;
char *output = "output image";
RNG rng;
void Coutours_Demo(int, void*);
int main()
{
	//加载图像
	src = imread("E:\\vs2015\\opencvstudy\\27police.jpg");
	if (!src.data)
	{
		cout << "could not load image!" << endl;
		return -1;
	}
	imshow("inputImage", src);
	cvtColor(src, src, CV_BGR2GRAY);
	imshow("grayImage", src);
	namedWindow(output, CV_WINDOW_AUTOSIZE);
	createTrackbar("Size", output, &threshold_value, threshold_max, Coutours_Demo);
	Coutours_Demo(0, 0);

	waitKey(0);
	return 0;
}

void Coutours_Demo(int, void*)
{
	Mat canny_output;
	Canny(src, canny_output, threshold_value, threshold_value * 2, 3, false);
	vector<vector<Point>> contours;  //数组..全部发现的轮廓对象
	vector<Vec4i> hierachy;//图的拓步结构
	findContours(canny_output, contours, hierachy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0));

	dst = Mat::zeros(src.size(), src.type());
	RNG rng(12345);
	for (size_t i = 0; i < contours.size(); i++)
	{
		Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));
		drawContours(dst, contours, i, color, 2, 8, hierachy, 0, Point(0, 0));
	}
	imshow(output, dst);
}

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

chde2Wang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值