-
Notifications
You must be signed in to change notification settings - Fork 0
/
code_color.py
36 lines (27 loc) · 1.14 KB
/
code_color.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
#Created by Shikha Singh
import cv2
#Creating a function to generate live sketch of the object detected by webcam
def sketch(img):
#The 'if' statement is used to check that images are passed correctly
if img is not None:
print("image is present")
print(len(img.shape))
return img
#Creating a cap variable which pulls image from the webcam
cap=cv2.VideoCapture(1)
#running a loop, else the cap variable will capture image of a particular instant
while True:
#'frame' refers to the actual image captured from the webcam
ret,frame=cap.read()
#applying an 'if' condition to check if captured image is detected in the program
if frame is not None:
print("frame present")
#the 'imshow' function is used for displaying the openCV window with the desired output
cv2.imshow('live sketcher',sketch(frame))
#waitKey() function allows to input an information when a window is open
#applying condition for detection of enter key
#thus, the program terminates when user presses Enter key
if cv2.waitKey(1)==13:
break
cap.release()
cv2.destroyAllWindows()