我有一些带有折线/多重曲线组合的图像。我的目标是恢复沿着这些折线/多重曲线的点的有序列表。
使用 opencv ConnectedComponents 我可以隔离图像中的每条折线/曲线,然后尝试通过以下步骤获取有序的点序列:
num_labels, labels_im = cv2.connectedComponents(input_image)
ske = skimage.morphology.skeletonize(labels_im==1)
x,y =np.where(ske)
cnt = np.vstack([x,y]).T.reshape(-1, 1, 2)
recovered_points = cv2.approxPolyDP(cnt, 100, False)
However, the points in recovered_points don't follow along the original polyline, they are points on the original polyline but in raster order, from let to right, bottom to top, and that's not what I want. Below you can see the input_image(original image), the skeleton image, and the recovered_points points (notice they came out rotated).
我还尝试在 input_image 的连接组件上使用 findContours,然后在轮廓上使用 approxPolyDP,但这些是原始折线周围的轮廓,因此恢复的点在一侧沿着折线移动,在另一侧沿着折线返回,并在第一点,这都不是我想要的。请参阅下面提取的轮廓的图像。
opencv 或 scikit-image 或其他库中是否有可以恢复沿原始折线/曲线的有序点?