本文介绍了在OpenCV / Python中给出一个描绘“S”形状边缘的轮廓,可以使用什么方法沿着形状的中心跟踪曲线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个描绘字母S边缘的轮廓(例如,在漫画中),如何获得沿着这个字母的脊的一系列点,以便以后使用线,三次样条或其他曲线来表示这个形状 - 代表技术?



我想使用Python / OpenCV中的30-40点来处理和表示形状。形态骨架化可以帮助这个,但操作总是似乎产生错误的分支。是否有更好的方法将轮廓折叠成字母的S形?





在下面的例子中,你可以看到错误的蛇的舌头骨架化。我不知道是否公平地说他们是错误的,如果这是算法应该做的,但对我来说,我不想他们在那里。



>



以下是漫画的字母表:





骨架化的另一个问题是计算成本高昂,但如果你知道一种使它成形的方法

解决方案

实际上,矢量化字体不是微不足道的问题,很棘手。要使用贝塞尔曲线正确地矢量化字体,您将需要跟踪。您可以使用许多库来跟踪图片,例如是相当复杂的,但是可用于显示向量字体的最佳算法之一:


  1. 查找轮廓(与方法A相同)

  2. 使用RDP与方法A不同,使用RDP删除点,

  3. 使用本文中描述的方法在外边缘绘制贝塞尔曲线

>


Given a contour outlining the edge of the letter S (in comic sans for example), how can I get a series of points along the spine of this letter in order to later represent this shape using lines, cubic spline or other curve-representing technique? I want to process and represent the shape using 30-40 points in Python/OpenCV.

Morphological skeletonization could help with this but the operation always seems to produce erroneous branches. Is there a better way to collapse the contour into just the 'S' shape of the letter?

In the example below you can see the erroneous 'serpent's tongue' like branches that are produced by morphological skeletonization. I don't know if it's fair to say they are erroneous if that's what the algorithm is supposed to be doing, but for me I would not like them to be there.

Below is the comic sans alphabet:

Another problem with skeletonization is that it is computationally expensive, but if you know a way of making it robust to forming 'serpent's tongue' like branches then I will give it a try.

解决方案

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.

  1. Find contour/edge of the object, you can use OpenCV function findContours()
  2. 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.
  3. 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:

  1. Find contour (the same with method A)
  2. Use RDP, differently from method A, use RDP to remove points so the contour can be simplified.
  3. Do delaunay triangulation.
  4. Draw bezier curve on the outer edges using method described in the paper

这篇关于在OpenCV / Python中给出一个描绘“S”形状边缘的轮廓,可以使用什么方法沿着形状的中心跟踪曲线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 01:09