提取描述工程图中线条的点

I have a black and white image of line drawings that may look something like the following: o

但可能要复杂得多。

I want to convert this drawing into a std::vector<std::vector<cv::Point>> (pretty much a contour). Except the problem is i cant simply call contour. Calling contour will give me an ordered set of points which outline this shape. I want ordered set of points (maybe even multiple of them) that will give me back the line itself.

这非常接近轮廓问题,只是需要“一半”的点数。

我写了一种方法,可以找到“连接器”的点和“ endPoints”的点。

因此,在示例中,有3个端点和1个连接器。

我的算法如下:

get actual contours = [[contour]]
classify points to get [endPoints], [connections] map

criticalSeen = 0
for each contour in contours
     If seen[current point] continue;

     If criticalSeen >= 1
          append current point to currPoints
          seen[current point] = true
     If criticalSeen == 0
         continue

     If criticalSeen == 2
          criticalSeen = 1
          append currPoints to result
          reset currPoints to empty
return result