相关疑难解决方法(0)

用于提取轮廓的骨架化图像中的问题

我发现这段代码可以获得一个镂空图像.我有一张圆圈图片(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)
Run Code Online (Sandbox Code Playgroud)

问题是图像结果不是"骨架"而是一组点!我的目的是在我对图像进行镂空后提取轮廓周长.如何编辑我的代码来解决它?使用cv2.findContours找到骨架圆是正确的吗?

python opencv feature-extraction contour computer-vision

3
推荐指数
1
解决办法
3835
查看次数