This code is based on the OpenCV Age Detection with Deep Learning by Adrian Rosebrock, which performs automatic age detection/prediction using OpenCV, Deep Learning and Python.
It has been refined and includes gender detection as extra feature. This code only works with static images.
The code follows a simple approach:
- Detect faces un the input image/video stream
- Extract the ROI and apply age and gender detector algorithm to predict the age and gender of the person.
Follow Adrian's tutorial to learn more about it.
To properly run this example you will need to have Python installed (Anaconda distribution) and OpenCV. The code uses pre-trained Caffe models, that you can find located in the folders face_detector
, age_detector
, gender_detector
.
- Fork the repo.
- Clone your forked repo.
- Locate a picture on the images folder and run the following code:
Run python detect.py --image images/[your_image_name] --face face_detector --age age_detector --gender gender_detector --confidence [confidence(0-1)]
Most of the code is extracted directly from Adrian's repository. Only the gender detection was added as extra. If you have any questions regarding this particular case, you can contact me through my email or instagram.