Skip to content

OpenCV is short for Open Source Computer Vision. Intuitively by the name, it is an open-source Computer Vision and Machine Learning library. This library is capable of processing real-time images and videos while also boasting analytical capabilities.

Notifications You must be signed in to change notification settings

MohammedNayeem9/Age-and-Gender-Detection-using-OpenCV-in-Python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gender and Age Detection with OpenCV

OpenCV is short for Open Source Computer Vision. Intuitively by the name, it is an open-source Computer Vision and Machine Learning library. This library is capable of processing real-time images and videos while also boasting analytical capabilities.

Today, we will use OpenCV to accurately identify the gender and age of a person from a single image of a face. The predicted gender may be one of ‘Male’ and ‘Female’, and the predicted age may be one of the following ranges- (0–2), (4–6), (8–12), (15–20), (25–32), (38–43), (48–53), (60–100).

Step 1: Detect face from the input image

The face detector produces the bounding box coordinates of the face in the image. Start by importing required libraries and finding the bounding box coordinates.

The getFaceBox() function is used to get the coordinates of the face. In the first three lines, we get the shallow copy of the frame and then we detect the height and width of the frame. Next, we construct a blob from it and pass the blob through the network to obtain the face detections. And finally, loop over the detections and extract the face coordinates. Use these coordinates to create a rectangle around the face.

Step 2: Load models

In the next lines, define the path of the face detection, age detection, and gender detection models.

Step 3: Defining the list of age buckets and gender

Initialize the mean values for the model and the lists of age ranges and genders to classify from.

Step 4: Function to predict the age and gender

After getting the face boxes, we create a 4-dimensional blob from the image. In doing this, we scale it, resize it, and pass in the mean values. We pass the blob through the gender detection model and get the confidence of the two-class (Male & Female). Whichever is higher, that is the gender of the person in the picture. Then follow the same procedure for age detection.

Step 5: Testing

About

OpenCV is short for Open Source Computer Vision. Intuitively by the name, it is an open-source Computer Vision and Machine Learning library. This library is capable of processing real-time images and videos while also boasting analytical capabilities.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published