ApproxPolyDP () function in OpenCV, opencvapproxpolydp

Source: Internet
Author: User

ApproxPolyDP () function in OpenCV, opencvapproxpolydp

CV_EXPORTS_W void approxPolyDP (InputArray curve,
OutputArray approxCurve,
Double epsilon, bool closed );

@ Param curve Input vector of a 2D point stored in std: vector or Mat
@ Param approxCurve Result of the approximation. The type shocould match the type of the input curve.
@ Param epsilon Parameter specifying the approximation accuracy. This is the maximum distance
Between the original curve and its approximation.
@ Param closed If true, the approximated curve is closed (its first and last vertices are
Connected). Otherwise, it is not closed.

The function cv: approxPolyDP approximates a curve or a polygon with another curve/polygon with less
Vertices so that the distance between them is less or equal to the specified precision. It uses
Douglas-Peucker algorithm

The main function is to break a continuous smooth curve into a line:

There are four parameters:

InputArray curve: Input curve. The data type can be vector <Point>.

OutputArray approxCurve: output line. The data type can be vector <Point>.

Double epsilon: threshold for determining the distance from a point to the corresponding line segment. (If the distance exceeds this threshold, it is discarded. If the distance is smaller than this threshold, it is retained. The smaller the epsilon, the closer the curve is .)

Bool closed: indicates whether the curve is closed.

Program example:

# Include <opencv2/opencv. hpp> # include <iostream> using namespace std; using namespace cv; void main () {Mat srcImg = imread ("01.jpg"); imshow (" src ", srcImg ); mat dstImg (srcImg. size (), CV_8UC3, Scalar: all (0); // pure black image cvtColor (srcImg, srcImg, CV_BGR2GRAY); threshold (srcImg, srcImg, 200,255, cosine ); vector <Point> contours; vector <Vec4i> hierarcy; findContours (srcImg, contours, hierarcy, 0, CV_CHAIN_APPROX_NONE); vector <Point> s_s_poly (contours. size (); // used to store a broken line point set for (int I = 0; I <contours. size (); I ++) {approxPolyDP (Mat (contours [I]), contours_poly [I], 15, true); drawContours (dstImg, contours_poly, I, scalar (0,255,255), 2, 8); // draw} imshow ("approx", dstImg); waitKey (0 );}

Image 201701.jpg ":

Epsilon is 15:

 

 

Epsilon is 5:

 

 

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.