Open setphen opened 7 years ago
I found a snippet here which describes the implementation https://forum.openframeworks.cc/t/contour-polyline-simplification/4461
But I change a line in the block
result = cvApproxPoly
(
&contour,
sizeof( CvContour ),
storage,
CV_POLY_APPROX_DP,
cvContourPerimeter( &contour ) * tolerance,
0
);
to
result = cvApproxPoly
(
&contour,
sizeof( CvContour ),
storage,
CV_POLY_APPROX_DP,
tolerance,
0
);
in order to have a consistent tolerance (epsilon, according the algorithm) instead of adjusting it based on the contour perimeter length. This keeps simplified vertices more consistent and defined, rather than jumping around.
I'm not sure a wrapper is necessary here, if you need to use the function, just do it like your code snippet does.
I really want to utilize the polygon approximation function approxPolyDP, which is part of opencv/imgproc opencv doc reference here
I don't have enough knowledge currently to write the wrapper myself - Are there significant difficulties in wrapping this feature? If I can get it working, I will see if I can make a pull request.