Face Detection using Open-cv

Giri Prasath.D
2 min readJun 5, 2021

--

Face Detection using Open CV and HaarCascades

This requires Open CV, Python, HaarCascades training data and suitable OS platform (Mac, Linux or Windows). For specific version please check vendor websites for the latest.

I used Python 3.9.4 on a test machine running Windows 10

To determine which version of Python you have installed,

Type the following on command prompt:

python — version

OpenCV 3.4.3 was used with this project, suitable for Python 2.7.14.

To determine if you have properly installed OpenCV, type the following from the python command line:

pip install opencv-python

see this website for further classification

https://pypi.org/project/opencv-python/

import cv2

Images used in this project were set to a resolution of 500 x 331 pixels (JPEG)

For documentation, please read:

code for the face detectionimport cv2 # Gets the name of the image file (filename) 
from sys.argv
imagePath = #enter the image path here
cascPath = “haarcascade_frontalface_default.xml”
`# This creates the cascade classifcation from file
faceCascade = cv2.CascadeClassifier(cascPath)
# The image is read and converted to grayscale
image = cv2.imread(imagePath)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# The face or faces in an image are detected
# This section requires the most adjustments to get accuracy on face being detected.
faces = faceCascade.detectMultiScale( gray,
scaleFactor=1.1,
minNeighbors=5,
minSize=(1,1),
flags = cv2.CASCADE_SCALE_IMAGE )
print(“Detected {0} faces!”.format(len(faces)))
# This draws a green rectangle around the faces detected
for (x, y, w, h) in faces:
cv2.rectangle(image, (x, y), (x+w, y+h), (255,0,0), 2) cv2.imshow(“Faces Detected”, image)
cv2.waitKey(0
)

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Giri Prasath.D
Giri Prasath.D

Written by Giri Prasath.D

🚀 Data enthusiast with expertise in Neo4j & MongoDB (2+ yrs) 🌐. Certified in AWS, Azure 📜. Solving data challenges with KNIME, PySpark & Enso

No responses yet

Write a response