backbone 化的过程产生大致表示形状的 backbone 的图像,但它不是轮廓。如何将 backbone 转换为轮廓?
使用以下OpenCV/Python代码,您可以完成以下's.png'图像的 backbone 化过程:
import numpy as np
import cv2, cv
img = cv2.imread("s.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_ELLIPSE,(3,3))
done = False
img =cv2.bitwise_not(img)
original = img
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("original", original)
cv2.imshow("skeleton",skel)
cv2.imshow("dilate-skeleton",cv2.dilate(skel, element))
3条答案
按热度按时间mu0hgdu01#
结果:
brgchamk2#
might wanna use from skimage.morphology import skeletonize https://scikit-image.org/docs/stable/auto_examples/edges/plot_skeleton.html
46scxncf3#
您正在寻找
findcontours()
函数http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html?highlight=find%20contour#findcontours