title: How to convert contours found by OpenCV into smooth splines or Bezier-like curves
body: <p>I'm vectorizing a color bitmap: shortly, I find the number of colors, extract each color as b/w mask, and detect contours, then dump everything into the file as SVG. But the result is poor due to very crispy and rough contours for the color edges. Also, I get a lot of noise (&quot;salt and pepper&quot;) which adds too many small contours to the output.</p>
  <p><img src="https://i.imgur.com/qEQnrDa.png" alt="Issues" /></p>
  <p>In order to eliminate &quot;salt and pepper&quot; I've tried to apply different blur effects (median blur, gaussian) prior to contour detection as well as morphological operators (erode/dilate/open/close), they all are not suitable for my case, because they blur or even remove tiny objects/contours that must stay sharp.</p>
  <p>Finally, I ended up with an idea to convert a set of points from detected contours into a spline or Bezier curve, but haven't found a way to do that with the arrays returned by cv2.findContour(...).</p>
  <p>As an experiment, I tried to apply <code>c = cv2.approxPolyDP(c, simplification_param, False)</code> to the contours but they become more angular and broken, rather than smooth and continuous.</p>
  <p>Is there a way to convert the result of cv2.approxPolyDP(...) into splines or use some other library to get the same results like approxPolyDP but with Bezier curves?</p>
  <p>These are the examples of b/w masks that I use to determine contours via cv2.findContours(...). Ultimately, they should be converted into smooth continuous curves (not necessarily connected or closed contours).</p>
  <p><img src="https://i.imgur.com/z8Q8The.png" alt="Mask" /></p>
  <p><img src="https://i.imgur.com/kGFXiwN.png" alt="Mask" /></p>
  <p>Thanks!</p>