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 should 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 (their first and last vertices are
Connected). Otherwise, it's not closed.
The function CV::APPROXPOLYDP approximates a curve or a polygon with another curve/polygon with less
Vertices so, the distance between them is less or equal to the specified precision. It uses the
Douglas-peucker algorithm
The main function is to line up a continuous smooth curve:
There are 4 parameters:
Inputarray curve: Input curve, data type can be vector<point>.
Outputarray approxcurve: Output polyline, data type can be vector<point>.
Double epsilon: Determines the threshold of the distance from the point to the corresponding line segment. (a distance greater than this threshold is discarded, less than this threshold is retained, and the smaller the epsilon, the more closely the shape of the polyline is "closer" to the curve.) )
BOOL closed: Whether the curve is a closed flag bit.
Examples of programs:
#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, 255, CV_THRESH_BINARY_INV);vector<vector<point>> contours;vector<vec4i> Hierarcy; Findcontours (srcimg, contours, Hierarcy, 0, Cv_chain_approx_none);vector<vector<point>> Contours_poly ( Contours.size ());//For storing the polyline point set for (int i = 0; I<contours.size (); i++) {APPROXPOLYDP (Mat (Contours[i]), Contours_poly[i] , Rawcontours, True);d (dstimg, Contours_poly, I, Scalar (0, 255, 255), 2, 8); Draw}imshow ("approx", dstimg); Waitkey (0);}
Image "01.jpg":
Epsilon is 15:
Epsilon is 5:
APPROXPOLYDP () function in OpenCV