-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlive-sketching.py
39 lines (30 loc) · 1.02 KB
/
live-sketching.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import keras
import cv2
import numpy as np
import matplotlib.pyplot as plt
print (cv2.__version__)
import cv2
import numpy as np
# Our sketch generating function
def sketch(image):
# Convert image to grayscale
img_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Clean up image using Guassian Blur
img_gray_blur = cv2.GaussianBlur(img_gray, (5,5), 0)
# Extract edges
canny_edges = cv2.Canny(img_gray_blur, 20, 50)
# Do an invert binarize the image
ret, mask = cv2.threshold(canny_edges, 70, 255, cv2.THRESH_BINARY_INV)
return mask
# Initialize webcam, cap is the object provided by VideoCapture
# It contains a boolean indicating if it was sucessful (ret)
# It also contains the images collected from the webcam (frame)
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
cv2.imshow('Our Live Sketcher', sketch(frame))
if cv2.waitKey(1) == 13: #13 is the Enter Key
break
# Release camera and close windows
cap.release()
cv2.destroyAllWindows()