-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbasic_camera.py
More file actions
31 lines (24 loc) · 781 Bytes
/
basic_camera.py
File metadata and controls
31 lines (24 loc) · 781 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
31
import cv2
cap = cv2.VideoCapture(0)
faceCascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
while True:
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(gray,1.1, 5)
count = 0
for (x, y, w, h) in faces:
roi_gray = gray[y: y+h, x: x+w]
roi_color = frame[y: y+h, x: x+w]
color = (255, 0, 0)
stroke = 2
cv2.rectangle(frame, (x, y), (x+w, y+h), color, stroke)
img = 'img_'+str(count)+".png"
count += 1
cv2.imwrite(img, roi_color)
print(x, y, w, h)
cv2.imshow('frame', frame)
k = cv2.waitKey(30) & 0xff
if k==27:
break
cap.release()
cv2.destroyAllWindows()