我绘制了 2,4 或 6 个直径的车轮骨架图像。我也有分支点坐标。
我想到了两种检测不同车轮的方法:
- 计算圆圈内的黑色区域
- 计算绘制的直径
在这两种情况下,我都不知道如何实现它们。
如您所见,车轮并不是完美的镂空,因此更难检测差异。
这是我用于骨架化的代码:
首先我对图像进行二值化,然后膨胀然后骨架化。
from skimage import io
import scipy
from skimage import morphology
import cv2
from scipy import ndimage as nd
import mahotas as mah
import pymorph as pm
import pymorph
complete_path = "wheel1.jpg"
gray = cv2.imread(complete_path,0)
print(gray.shape)
cv2.imshow('graybin',gray)
cv2.waitKey()
ret,thresh = cv2.threshold(gray,127,255,cv2.THRESH_BINARY_INV)
imgbnbin = thresh
print("shape imgbnbin")
print(imgbnbin.shape)
cv2.imshow('binaria',imgbnbin)
cv2.waitKey()
element = cv2.getStructuringElement(cv2.MORPH_CROSS,(6,6))
graydilate = cv2.dilate(imgbnbin, element) #imgbnbin
graydilate = cv2.dilate(graydilate, element)
#graydilate = cv2.erode(graydilate, element)
cv2.imshow('dilate',graydilate)
cv2.waitKey()
#SKELETONIZE
out = morphology.skeletonize(graydilate>0)
skel = out.astype(float)
cv2.imshow('scikitimage',skel)
cv2.waitKey()
io.imsave('wheel.jpg', skel)
sk = skel
print(sk.shape)
原始图像: