我找到这段代码是为了得到一个骷髅图像。 我有一个圆形图像(https://docs.google.com/file/d/0ByS6Z5WRz-h2RXdzVGtXUTlPSGc/edit?usp=sharing)。在
img = cv2.imread(nomeimg,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
print("skel")
print(skel)
cv2.imshow("skel",skel)
cv2.waitKey(0)
问题是图像结果不是一个“骨架”,而是一组点! 我的目的是在对图像进行骨架化后提取轮廓周长。 如何编辑我的代码来解决它? 用cv2.findContours找到骨架圆是正确的吗?在
您需要反转黑白,并通过首先调用
cv2.dilate
来填充所有空白:结果如下:
但是,结果并不好,因为还有很多差距。以下算法更好,它使用
^{pr2}$scipy.ndimage.morphology
中的函数:结果是:
骨架化算法计算白色区域的骨架:
要修复代码,可以更改阈值函数的参数:
参数描述为here。在
相关问题 更多 >
编程相关推荐