From 019b10fcbce2844d437271bae05ab91c57f86f4e Mon Sep 17 00:00:00 2001 From: Tim Date: Sat, 6 Feb 2021 18:32:39 -0500 Subject: [PATCH] added tutorial 8 --- tutorial8.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tutorial8.py diff --git a/tutorial8.py b/tutorial8.py new file mode 100644 index 0000000..e24ca36 --- /dev/null +++ b/tutorial8.py @@ -0,0 +1,27 @@ +import numpy as np +import cv2 + +cap = cv2.VideoCapture(0) +face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml') +eye_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_eye.xml') + +while True: + ret, frame = cap.read() + + gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) + faces = face_cascade.detectMultiScale(gray, 1.3, 5) + for (x, y, w, h) in faces: + cv2.rectangle(frame, (x, y), (x + w, y + h), (255, 0, 0), 5) + roi_gray = gray[y:y+w, x:x+w] + roi_color = frame[y:y+h, x:x+w] + eyes = eye_cascade.detectMultiScale(roi_gray, 1.3, 5) + for (ex, ey, ew, eh) in eyes: + cv2.rectangle(roi_color, (ex, ey), (ex + ew, ey + eh), (0, 255, 0), 5) + + cv2.imshow('frame', frame) + + if cv2.waitKey(1) == ord('q'): + break + +cap.release() +cv2.destroyAllWindows() \ No newline at end of file