#include <opencv2/opencv.hpp>
//#include<iostream>
#include<time.h>
#include<windows.h>
using namespace cv;
using namespace std;
int main()
{
long start_time = GetTickCount(); //获取此程序段开始执行时间
Mat image = imread("4.jpg");
imshow("Source Image", image);
Mat gray;
cvtColor(image, gray, CV_BGR2GRAY);
GaussianBlur(gray, gray, Size(3, 3), 3, 3);
Mat img;
threshold(gray, img, 0, 255, THRESH_OTSU);
imshow("gray", gray);
Mat img1;
img.copyTo(img1);
vector<vector<Point>> contours;
vector<Vec4i> hierarchy;
findContours(img, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_NONE);
Mat resultImage = Mat::zeros(img.size(), CV_8U);
drawContours(resultImage, contours, -1, Scalar(255, 0, 255));
long end_time = GetTickCount(); //获取此程序段开始执行时间
cout << "程序段运行时间:" << (end_time - start_time) << "ms!" << endl; //差值即执行时间
imshow("目标图像", resultImage);
waitKey(0);
cin.get();
return 0;
}