1 使用cv2,将图片改为素描图,效果如图:
2 代码实现:
python 3.8
import cv2img = cv2.imread("2.jpg")
# 灰度
grey = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
invert = cv2.bitwise_not(grey)
# 高斯滤波
blur_img = cv2.GaussianBlur(invert, (7, 7), 0)
inverse_blur = cv2.bitwise_not(blur_img)
sketch_img = cv2.divide(grey, inverse_blur, scale=256.0)
cv2.imwrite("sketch.jpg", sketch_img)
cv2.waitKey(0)
cv2.destroyAllWindows()