OpenCV finding outlines by cvfindcontours and cvdrawcountours functions

Source: Internet
Author: User

findcontours looking for contours in binary images [CPP] view plain copy int cvfindcontours (cvarr* image, cvmemstorage* storage, cvseq** first_contour,int header_s Ize=sizeof (cvcontour), int mode=cv_retr_list, int method=cv_chain_approx_simple, Cvpoint offset=cvpoint (0,0));

Image
The input 8-bit, single-channel image. Non-0 elements are treated as 1, 0 pixels are reserved as 0-thus the image is treated as a binary value. In order to get such a two value image from a grayscale image, you can use Cvthreshold, Cvadaptivethreshold, or Cvcanny. This function changes the input image content.
Storage
The resulting outline of the storage container
First_contour:
Output parameters: A pointer containing the first output outline
Header_size:
If Method=cv_chain_code, the size of the sequence header is >=sizeof (cvchain), otherwise >=sizeof (Cvcontour).
Mode
Extraction mode.
Cv_retr_external-Extracts only the outermost contours
Cv_retr_list-Extracts all outlines and places them in the list
Cv_retr_ccomp-Extracts all contours and organizes them into a layer two hierarchy: The top layer is the perimeter boundary of the connected domain, and the secondary layer is the inner boundary of the hole.
Cv_retr_tree-Extracts all contours and reconstructs all hierarchy of nested outlines
Method
Approximation method (for all nodes, excluding cv_retr_runs using internal approximation).
Cv_chain_code-freeman the output profile of the chain code. Other methods output polygons (fixed-point sequences).
Cv_chain_approx_none-converts all points from chain code form to point sequence form
Cv_chain_approx_simple-Compress horizontal, vertical, and diagonal splits, i.e. the function retains only the pixel points of the end;
CV_CHAIN_APPROX_TC89_L1,
Cv_chain_approx_tc89_kcos-Application of Teh-chin chain approximation algorithm. Cv_link_runs-Uses a completely different contour extraction algorithm with horizontal fragments connected to 1. Only Cv_retr_list extraction mode can be applied in this method.
Offset
The offset of each contour point. When the contour is extracted from the ROI of the image, it is useful to use offsets because the contour can be analyzed from the entire image context.
The function cvfindcontours extracts the contour from a two-value image and returns the number of extracted outlines. The contents of the pointer first_contour are filled in by the function. It contains a pointer to the first outermost outline, and if the pointer is NULL, no contour is detected (for example, the image is completely black). Other contours can be accessed from first_contour using H_next and V_next links. The sample in cvdrawcontours shows how to use the contour to detect connected domains. Profiles can also be used for shape analysis and object recognition-see the squares example in the CVPR2001 tutorial. This tutorial can be found on the SourceForge website.

Drawcontours draws the outer and inner outlines in the image. [CPP] view plain copy void Cvdrawcontours (Cvarr *img, cvseq* contour,cvscalar external_color, Cvscalar ho Le_color,int max_level, int thickness=1,int line_type=8, cvpoint offset=cvpoint (0,0));

Img:
The image used to draw the contour. As with other plotting functions, boundary images are clipped by the area of interest (ROI).
Contour

The pointer points to the first outline.
External_color:

The color of the outer contour.
Hole_color:

The color of the inner contour.
Max_level:

The maximum level for drawing outlines. If the level is 0, draw a separate outline. If 1, the contour is drawn and the outline follows the same level. If the value is 2, all the outlines. If the level is 2, draw all the sibling contours and all the low-level outlines. If the value is negative, the function does not draw the sibling outline, but is drawn in ascending order to the sub-contour of ABS (Max_level)-1.
Thickness

The thickness of the line used to draw the outline. If the value is negative (e.g. =cv_filled), the inner contour is drawn.
Line_type:

The type of the line. Refer to Cvline.
Offset

Moves each contour point coordinate according to the given offset. This parameter is used when the contour is extracted from certain areas of interest (ROI) and then needs to be considered for the ROI offset in the operation.

When thickness>=0, the function cvdrawcontours the outline in the image, or when thickness<0, the area to which the fill outline is limited

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.