import cv2
img = cv2.imread('corgi.jpg')
data = (150, 150)
imgCanny = cv2.Canny(img, *data)
# 创建矩形结构
g = cv2.getStructuringElement(cv2.MORPH_RECT, (5, 7))
# 膨化处理
img_dilate = cv2.dilate(imgCanny, g)
shape = img_dilate.shape
# 提取
for i in range(shape[0]):
for j in range(shape[1]):
if img_dilate[i, j] == 0: # 二维定位到三维
img[i, j] = [0, 0, 0]
cv2.imshow('title', img)
cv2.waitKey()
cv2.destroyAllWindows()