Skip to content

Commit

Permalink
added tutorial 8
Browse files Browse the repository at this point in the history
  • Loading branch information
techwithtim committed Feb 6, 2021
1 parent 941d2bf commit 019b10f
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tutorial8.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 019b10f

Please sign in to comment.