Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
so i am trying to implement a face detection age classifying agent that detects a face on a photo and then classifies it according to age as 'Old' and 'Young'. So far I have implemented the face recognition class using OpenCV in which I used the Haar Cascade and thus the code will detect the face of the person on the photo and label it with a square. However, I dont know what the next steps are .

What I have tried:

Here is the code of the face detection class:

<pre>import cv2

# Load the cascade
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')

#eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')

# Read the input image
img = cv2.imread('IMG_2017.JPG')

# Convert into grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# Detect faces
faces = face_cascade.detectMultiScale(gray, 1.1, 4)
#Detect eyes
#eyes = eye_cascade.detectMultiScale(gray, 1.1, 12)

# Draw rectangle around the faces
for (x, y, w, h) in faces:
    cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)


#for (x, y, w, h) in eyes:
 #   cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2)

# Display the output
cv2.imshow('img', img)
cv2.waitKey()

What are my next steps to proceed with my project?
Posted
Updated 21-Oct-20 10:14am
v2
Comments
[no name] 20-Oct-20 21:07pm    
You differentiate "old" and "not old" faces and use that data for model training and testing.
Supoh 21-Oct-20 6:19am    
ok so i need a dataset for my model but how do i implement the training part any ideas?
[no name] 21-Oct-20 8:59am    
Your ears and nose get bigger as you age; also, most men loose their hair. Scan for bald people with long noses and ears. And bigger feet.

1 solution

Based on different facial feature you need to define a confidence factor for defining an age. Train the model with datasets (images). Would suggest CNN (Neural Network) for this classification.

Quote:
In order to evaluate an age detector, you cannot rely on the person’s actual age. Instead, you need to measure the accuracy between the predicted age and the perceived age

Following articles can guide you further:
OpenCV Age Detection with Deep Learning - PyImageSearch[^]
Gender and Age Classification using Deep Learning | Learn OpenCV[^]
Predict Age and Gender Using Convolutional Neural Network and OpenCV[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900