Skip to content
Advertisement

Is there a way to use cv2.approxPolyDP to approximate open curve?

I would like to approximate smooth lines with chain of line segments.

cv2.approxPolyDP in OpenCV 3.4 made a good result in the case of closed curve.

Origin close curve: Origin close curve Approximated close curve: Approximated close curve

But in the case of open curve, cv2.approxPolyDP did not achieve the desired effect.

Origin open curve: Origin open curve Approximated open curve: Approximated open curve

The result I want should be one chain of line segments but not a closed polygon, like this(this picture is created by Photoshop but not Python program): enter image description here

Is there a way to use cv2.approxPolyDP to approximate open curve?

My Python program is as follow:

JavaScript

The origin photos used in my program are as follow.

Close curve photo Open curve photo

Advertisement

Answer

Here is how to do that in Python/OpenCV using cv2.approxPolyDP

Input (cropped off screen snap title bar)

enter image description here

JavaScript

enter image description here

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement