#include "stdafx.h"
#include<opencv2\highgui\highgui.hpp>
#include<opencv2\core\core.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include<iostream>
using namespace cv;
using namespace std;
int th = 60;
int th_max=255;
string winname = "qq";
Mat qq, qq1, dst, cout, dr, cny;
void demo(int, void*);
int main()
{
qq=imread("D:\\test.PNG");
if (qq.empty())
{
return -1;
}
//GaussianBlur(qq, qq1, Size(3,3), 0, 0);
medianBlur(qq, qq1, 3);
cvtColor(qq1, dst, CV_RGB2GRAY);
namedWindow(winname);
createTrackbar("yuzhi", winname, &th, th_max, demo);
demo(0, 0);
waitKey(0);
return 0;
}
void demo(int ,void*)
{
vector<vector<Point>> couts;
vector<Vec4i>h;
Canny(dst, cny, th, th_max, 3, false);
dr = Mat::zeros(qq.size(), qq.type());
findContours(cny, couts, h, RETR_TREE, CHAIN_APPROX_NONE);
for (size_t i = 0; i <couts.size(); i++)
{
drawContours(dr, couts, i, Scalar(0, 0, 255), 1, 8, h, 0, Point(0, 0));
}
imshow(winname, dr);
}