OpenCV Python中骨架化的另一种方法?

OpenCV Python中骨架化的另一种方法?,python,opencv,image-processing,signal-processing,feature-detection,Python,Opencv,Image Processing,Signal Processing,Feature Detection,我试图对下面的特征进行骨架化,以便提取关于1)特征长度2)特征曲率的信息。我遇到了这个问题,它反复侵蚀图像。下面显示的是结果——看起来很糟糕。有人能推荐一种不同的方法来骨架化我的特征吗 下面是上面链接中的示例: import cv2 import numpy as np img = cv2.imread('sofsk.png',0) size = np.size(img) skel = np.zeros(img.shape,np.uint8) ret,img = cv2.threshold

我试图对下面的特征进行骨架化,以便提取关于1)特征长度2)特征曲率的信息。我遇到了这个问题,它反复侵蚀图像。下面显示的是结果——看起来很糟糕。有人能推荐一种不同的方法来骨架化我的特征吗

下面是上面链接中的示例:

import cv2
import numpy as np

img = cv2.imread('sofsk.png',0)
size = np.size(img)
skel = np.zeros(img.shape,np.uint8)

ret,img = cv2.threshold(img,127,255,0)
element = cv2.getStructuringElement(cv2.MORPH_CROSS,(3,3))
done = False

while( not done):
    eroded = cv2.erode(img,element)
    temp = cv2.dilate(eroded,element)
    temp = cv2.subtract(img,temp)
    skel = cv2.bitwise_or(skel,temp)
    img = eroded.copy()

    zeros = size - cv2.countNonZero(img)
    if zeros==size:
        done = True

cv2.imshow("skel",skel)
cv2.waitKey(0)
cv2.destroyAllWindows()

我认为你应该反转图像,因为你的特征是黑色区域。需要骨骼化的对象必须是白色。