Opencv-image convex hull

Source: Internet
Author: User
# 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 );}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.