Search
 
SCRIPT & CODE EXAMPLE
 

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()
Comment

PREVIOUS NEXT
Code Example
Python :: count the number of rows in a database table in Django 
Python :: python test is nan 
Python :: pandas add list to dataframe as column 
Python :: redirect if not logged in django 
Python :: model checkpoint keras 
Python :: Python Program to count the number of lowercase letters and uppercase letters in a string. 
Python :: pandas filter length of string 
Python :: pandas not in list 
Python :: python convert bool to string 
Python :: python sentence splitter 
Python :: python var_dump 
Python :: how to get the current year in python 
Python :: round to the nearest integer python 
Python :: python parse url get parameters 
Python :: flask abort return json 
Python :: date colomn to datetime 
Python :: python program to solve quadratic equation 
Python :: install python in centos7 
Python :: tqdm python 
Python :: convert float to integer pandas 
Python :: python google chrome 
Python :: api testing with python 
Python :: python printing to a file 
Python :: print map object python 
Python :: python verzeichnis erstellen 
Python :: python zeros to nan 
Python :: numpy round to int 
Python :: install python 3.7 centos 
Python :: django content type 
Python :: python group by multiple aggregates 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =