-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathvideo.py
More file actions
30 lines (19 loc) · 755 Bytes
/
video.py
File metadata and controls
30 lines (19 loc) · 755 Bytes
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
import cv2
face_cascades = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
# img = cv2.imread('face.jpg')
# img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# faces = face_cascades.detectMultiScale(img_gray)
# for (x, y, w, h) in faces:
# cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)
# cv2.imshow('Result', img)
# cv2.waitKey(0)
cap = cv2.VideoCapture(0)
while True:
_, frame = cap.read()
img_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = face_cascades.detectMultiScale(img_gray)
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x + w, y + h), (255, 0, 0), 2)
cv2.imshow('Result', frame)
if cv2.waitKey(1) & 0xff == ord('q'):
break