Opencv convex packet Detection

Source: Internet
Author: User

# Include <cv. h>
# Include <cxcore. h>
# Include # Include <cvaux. h>
# Include <iostream>
Using namespace STD;

Int main ()
{
Iplimage * src = cvloadimage ("G: \ Users \ movingobjectdetector \ Result \ resultfor [g_85_flv] \ mask16.jpg", cv_load_image_grayscale );
Iplimage * DST = cvcreateimage (cvgetsize (SRC), 8, 3); cvzero (DST );
Cvmemstorage * storage = cvcreatememstorage ();
Cvseq * contour = NULL, * hull = NULL;

Cv1_1_1_= cvstartfindcontours (SRC, storage );
While (contour = cvfindnextcontour (timeout ))! = NULL ){
Cvdrawcontours (DST, contour, cv_rgb (255,0, 0), cv_rgb (0,255, 0), 0 );

Cout <cvcheck1_convexity (contour) <Endl;

Hull = cvconvexhull2 (contour, 0, cv_clockwise, 0);/* simple * // * Convex Hull for calculating known contours */

Cvpoint pt0 = ** (cvpoint **) cvgetseqelem (Hull, hull-> total-1 );
For (INT I = 0; I Cvpoint pt1 = ** (cvpoint **) cvgetseqelem (Hull, I );
Cvline (DST, pt0, pt1, cv_rgb (0, 0, 255 ));
Pt0 = pt1;
}

Cvseq * defect = cvconvexitydefects (contour, hull); // detect contour convex Defects

For (INT I = 0; I <defect-> total; ++ I ){
Cvconvexitydefect df = * (cvconvexitydefect *) cvgetseqelem (defect, I );
Cvcircle (DST, * DF. start, 2, cv_rgb (255,255, 0),-1); // corresponding to the convex points, link these points to form a multi-deformation, convex bag is
Cvcircle (DST, * DF. End, 2, cv_rgb (255, 0, 255),-1 );
Cvcircle (DST, * DF. depth_point, 2, cv_rgb (0,255,255),-1); // corresponding to the concave points
Cvline (DST, * DF. Start, * DF. depth_point, cv_rgb (0,255,255 ));
}

Cvshowimage ("DST", DST );
Cvwaitkey ();
}
Cvendfindcontours (& region );
}

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.