You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
679 B
20 lines
679 B
import cv2
|
|
|
|
if __name__ == '__main__':
|
|
input_img = r'C:\Users\Administrator\Desktop\Upload\d825cc1e-6518-afd5-1b02-ed88a7a72806.jpg'
|
|
|
|
|
|
image = cv2.imread(input_img)
|
|
imagename = str(input_img).split(".")[0]
|
|
|
|
# BGR2GRAY 转换成灰阶(黑白图)
|
|
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
|
cv2.imwrite(imagename + "_gray.jpg", gray_image)
|
|
|
|
# #反转片
|
|
inverted_image = 255 - gray_image
|
|
blurred = cv2.GaussianBlur(inverted_image, (21, 21), 0)
|
|
inverted_blurred = 255 - blurred
|
|
pencil_sketch = cv2.divide(gray_image, inverted_blurred, scale=256.0)
|
|
cv2.imwrite(imagename + "_pencil.jpg", pencil_sketch)
|