-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcheck_camera.py
35 lines (24 loc) · 897 Bytes
/
check_camera.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
def camer():
import cv2
# Load the cascade
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
# To capture video from webcam.
cap = cv2.VideoCapture(0)
while True:
# Read the frame
_, img = cap.read()
# Convert to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Detect the faces
faces = face_cascade.detectMultiScale(gray, 1.3, 5, minSize=(30, 30),flags = cv2.CASCADE_SCALE_IMAGE)
# Draw the rectangle around each face
for (x, y, w, h) in faces:
cv2.rectangle(img, (x, y), (x + w, y + h), (10,159,255), 2)
# Display
cv2.imshow('Webcam Check', img)
# Stop if escape key is pressed
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# Release the VideoCapture object
cap.release()
cv2.destroyAllWindows()