Given A Contour Outlining The Edges Of An 'S' Shape In OpenCV/Python, What Methods Can Be Used To Trace A Curve Along The Center Of The Shape?
Solution 1:
Actually vectorizing fonts isn't trivial problem and quite tricky. To properly vectorize fonts using bezier curve you'll need tracing. There are many library you can use for tracing image, for example Potrace. I'm not knowledgeable using python but based on my experience, I have done similar project using c++ described below:
A. Fit the contour using cubic bezier
This method is quite simple although a lot of work should be done. I believe this also works well if you want to fit skeletons obtained from thinning.
- Find contour/edge of the object, you can use OpenCV function findContours()
- The entire shape can't be represented using a single cubic bezier, so divide them to several segments using Ramer-Douglas-Peucker (RDP). The important thing in this step, don't delete any points, use RDP only to segment the points. See colored segments on image below.
- For each segments, where S is a set of n points S = (s0, s1,...Sn), fit a cubic bezier using Least Square Fitting
Illustration of least square fitting:
B. Resolution Resolution Independent Curve Rendering
This method as described in this paper is quite complex but one of the best algorithms available to display vector fonts:
- Find contour (the same with method A)
- Use RDP, differently from method A, use RDP to remove points so the contour can be simplified.
- Do delaunay triangulation.
- Draw bezier curve on the outer edges using method described in the paper
Solution 2:
The following simple idea might be usefull.
Calculate Medial axis of the outer contour. This would ensure connectivity of the curves.
Find out the branch points. Depending on its length you can delete them in order to eliminate "serpent's tongue" problem.
Hope it helps.
Post a Comment for "Given A Contour Outlining The Edges Of An 'S' Shape In OpenCV/Python, What Methods Can Be Used To Trace A Curve Along The Center Of The Shape?"