We would like to give some suggestions for you.
1. There are state of the art algorithms available for detecting age from images using machine learning and deep learning [Links are given below] .
2. We recommend to use such algorithms for your use case.
3. Once you are done with your training , You can extract the face region from the proposed image and give it as input for age prediction model.
4. Based on the prediction you can map the advertisement to the concerned age group.
Reference Links :