Image contour sag repair

Source: Internet
Author: User
Image contour sag repair








Profile convex shape can be considered as a simple sag repair without restrictions. In more general cases, the target object is generally convex, and the local area is slightly concave. If this type of target object exists
A very serious sag is usually caused by some interference factors that have not been detected. Contour repair in such cases is actually a kind of concave repair with conditions.

The SAG degree of the contour can be described by the ratio of the sag depth to the sag span. When the sag degree is not less than a given threshold value, the contour is repaired.


 


# Include "cxcore. H "<br/> # include" CV. H "<br/> # pragma comment (Lib," cxcore. lib ") <br/> # pragma comment (Lib," CV. lib ") <br/> // sag repair <br/> // parameter: <br/> // 1. pbinary: input binary image, single channel, bit depth ipl_depth_8u. <Br/> // 2. fconthre: SAG threshold. When the sag degree is less than or equal to fconthre, repair the fault. <Br/> void concavityrepair (iplimage * pbinary, float fconthre) <br/>{< br/> int I, dx, Dy; <br/> float fspan, fthreshold; <br/> cvseq * pcontour = NULL; <br/> cvseq * empty qhull = NULL; <br/> cvseq * empty qdefect = NULL; <br/> cvmemstorage * pstorage1 = NULL; <br/> cvmemstorage * pstorage2 = NULL; <br/> cvconvexitydefect * pdefect = NULL; <br/> // execution condition <br/> If (pbinary) <br/> {<br/> // search for all outlines <br/> pstorage 1 = cvcreatememstorage (0); <br/> pstorage2 = cvcreatemstorage (0); <br/> cvfindcontours (pbinary, pstorage1, & pcontour, sizeof (cvcontour), Region, region, cv_chain_approx_simple); <br/> // fill all outlines <br/> cvdrawcontours (pbinary, pcontour, cv_rgb (255,255,255), cv_rgb (255,255,255), 2, cv_filled, 8, cvpoint (0, 0); <br/> // external contour loop <br/> for (; pcontour! = NULL; pcontour = pcontour-> h_next) <br/> {<br/> // The convex shape of the contour <br/> 1_qhull = cvconvexhull2 (pcontour, null, cv_clockwise, 0); <br/> // contour convex defect <br/> initial qdefect = cvconvexitydefects (pcontour, precise qhull, pstorage2 ); <br/> // convex defect loop <br/> for (I = 0; I <pseqdefect-> total; I ++) <br/>{< br/> pdefect = (cvconvexitydefect *) cvgetseqelem (precise qdefect, I ); <br/> // concave span <br/> dx = pdefect-> Start-> X-pdefect-> end-> X; <br/> DY = pdefect-> Start-> Y-pdefect-> end-> Y; <br/> fspan = (float) (dx * dx + dy * Dy); <br/> // repair threshold <br/> fthreshold = pdefect-> depth * fconthre; <br/> fthreshold * = fthreshold; <br/> // sag repair <br/> If (fspan <= fthreshold) <br/> {<br/> cvline (pbinary, * pdefect-> start, * pdefect-> end, cv_rgb (255,255,255); <br/>}< br/> cvreleasemstorage (& pstorage1 ); <br/> cvreleasememstorage (& pstorage2); <br/> pstorage1 = NULL; <br/> pstorage2 = NULL; <br/>}< br/>}


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.