-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcv2_humandetect.py
More file actions
27 lines (20 loc) · 859 Bytes
/
Copy pathcv2_humandetect.py
File metadata and controls
27 lines (20 loc) · 859 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
import cv2
import numpy as np
cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)
cascade_path = cv2.data.haarcascades + "haarcascade_frontalface_default.xml"
face_cascade = cv2.CascadeClassifier(cascade_path)
while True:
ret, frame = cap.read()
frame = cv2.flip(frame, 1)
gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray_frame, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30))
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
roi = frame[y:y + h, x:x + w]
cv2.imshow("Insan", roi)
cv2.putText(frame, "Insan", (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2)
cv2.imshow("Webcam", frame)
if cv2.waitKey(1) & 0xFF == ord("q"):
break
cap.release()
cv2.destroyAllWindows()