Last active
March 30, 2022 16:08
-
-
Save hrialan/9a7887f7537fbd52abd54be83bca0614 to your computer and use it in GitHub Desktop.
[Picture to sketch] Small python code to draw a sketch from a picture #picture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
img_location = './' | |
filename = 'profil.jpg' | |
img = cv2.imread(img_location + filename) | |
def picture_to_sketch(img, color=False ,blur_kernel=40): | |
if not color : | |
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) | |
inverted_picture = cv2.bitwise_not(img) | |
blur_picture = cv2.blur(inverted_picture, (blur_kernel, blur_kernel)) | |
sketch = cv2.divide(img, 255 - blur_picture, scale=256) | |
return sketch | |
sketch = picture_to_sketch(img) | |
sketch_color = picture_to_sketch(img, color=True) | |
cv2.imwrite('sketch.jpg', sketch) | |
cv2.imwrite('sketch_color.jpg', sketch_color) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment