Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Make a Basic Face Detection Algorithm in Python Using OpenCV and Haar Cascades

import cv2
import matplotlib.pyplot as plt
import numpy as np
face_cascade = cv2.CascadeClassifier(
 'cascades/data/haarcascade_frontalface_alt2.xml')
cap = cv2.VideoCapture(0)
while True:
 ret, frame = cap.read()
 gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(
 gray_frame, scaleFactor=1.5, minNeighbors=5)
for (x, y, w, h) in faces:
 width = x + w
 height = y + h
 
 roi_frame = frame[x:x+h, y:y+h]

 cv2.rectangle(frame, (x, y), (width, height), (0, 0, 255), thickness=3)
cv2.imshow("main frame", frame)
if cv2.waitKey(0) & 0xFF == 27:
 break
cap.release()
cv2.destroyAllWindows()
Source by python.plainenglish.io #
 
PREVIOUS NEXT
Tagged: #Make #Basic #Face #Detection #Algorithm #Python #Using #OpenCV #Haar #Cascades
ADD COMMENT
Topic
Name
2+8 =