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