import cv2
import numpy as np
img = cv2.imread('./image/dog.png')
#注意调节kernel大小以获得更清晰的边缘
kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(7,7))
dst = cv2.morphologyEx(img,cv2.MORPH_BLACKHAT,kernel, iterations=1)
cv2.imshow('img', np.hstack((img, dst)))
cv2.waitKey(0)
cv2.destroyAllWindows()