# Include "opencv2/highgui. HPP "# include" opencv2/imgproc. HPP "# include <iostream> # include <stdio. h> # include <stdlib. h> using namespace CV; using namespace STD; mat src; MAT src_gray; int thresh = 100; int max_thresh = 255; RNG (12345 ); // function declaration void thresh_callback (INT, void *); int main (INT argc, char ** argv) {// load color image src = imread (argv [1], 1); // convert to a grayscale image and blur cvtcolor (SRC, src_gray, cv_bgr2gray); blur (src_gray, src_gray, size (3, 3 )); // create a window char * source_window = "Source"; namedwindow (source_window, cv_window_autosize); imshow (source_window, Src); createtrackbar ("threshold:", "Source", & Thresh, max_thresh, thresh_callback); thresh_callback (0, 0); waitkey (0); Return (0);} void thresh_callback (INT, void *) {mat src_copy = SRC. clone (); MAT threshold_output; vector <point> contours; vector <vec4i> hierarchy; // threshold value detection boundary threshold (src_gray, threshold_output, thresh, 255, thresh_binary ); // find the findcontours (threshold_output, contours, hierarchy, cv_retr_tree, cv_chain_approx_simple, point (0, 0 )); // search for the convex hull vector <point> hull (contours. size (); For (INT I = 0; I <contours. size (); I ++) {convexhull (MAT (contours [I]), hull [I], false);} // draw mat drawing = mat :: zeros (threshold_output.size (), cv_8uc3); For (INT I = 0; I <contours. size (); I ++) {scalar color = scalar (RNG. uniform (0,255), RNG. uniform (0,255), RNG. uniform (0,255); drawcontours (drawing, contours, I, color, 1, 8, vector <vec4i> (), 0, point (); drawcontours (drawing, Hull, i, color, 1, 8, vector <vec4i> (), 0, point ();} // display namedwindow ("hull Demo", cv_window_autosize ); imshow ("hull Demo", drawing );}