ofxCv icon indicating copy to clipboard operation
ofxCv copied to clipboard

Wrapper for approxPolyDP

Open setphen opened this issue 7 years ago • 2 comments

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.

setphen avatar Nov 07 '16 19:11 setphen

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.

setphen avatar Nov 07 '16 19:11 setphen

I'm not sure a wrapper is necessary here, if you need to use the function, just do it like your code snippet does.

avilleret avatar Feb 12 '17 10:02 avilleret