We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 46b7128 + 8fa43fb commit 4c513f4Copy full SHA for 4c513f4
python/face_eye_detector/code.py
@@ -0,0 +1,28 @@
1
+import cv2
2
+
3
+face_cascade = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
4
+eye_cascade = cv2.CascadeClassifier("haarcascade_eye.xml")
5
6
7
+def detect(gray, frame):
8
+ faces = face_cascade.detectMultiScale(gray, 1.3, 5)
9
+ for (x, y, w, h) in faces:
10
+ cv2.rectangle(frame, (x, y), (x + w, y + h), (255, 0, 0), 2)
11
+ roi_gray = gray[y : y + h, x : x + w]
12
+ roi_color = frame[y : y + h, x : x + w]
13
+ eyes = eye_cascade.detectMultiScale(roi_gray, 1.1, 3)
14
+ for (ex, ey, ew, eh) in eyes:
15
+ cv2.rectangle(roi_color, (ex, ey), (ex + ew, ey + eh), (0, 255, 0), 2)
16
+ return frame
17
18
19
+video_capture = cv2.VideoCapture(0)
20
+while True:
21
+ _, frame = video_capture.read()
22
+ gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
23
+ canvas = detect(gray, frame)
24
+ cv2.imshow("Video", canvas)
25
+ if cv2.waitKey(1) & 0xFF == ord("q"):
26
+ break
27
+video_capture.release()
28
+cv2.destroyAllWindows()
0 commit comments