1 | initial version |
Check out the Face detection module tutorial to detect the face. You should be able to directly apply it to extract the face (along with neck/torso and the surrounding background) as a Mat
object.
Are you using a camera with a stationary scene with faces popping in and out? In that case, subtracting a detected face from the background is quite straightforward. You will first need to save template background image Mat background_img
without any faces in the scene.
Once you detect a face as Mat roi
, find and extract the corresponding sub-region in bgrnd_img
to get roi_background_img
. Now you can simply perform subtraction: roi - roi_background_img
to get only the face (with the neck and parts of the torso).
Note: This will produce poor results if your illumination varies. In this case, you should threshold both roi
and roi_background_img
before subtraction.
Additionally, you can also check out this module for background subtraction.
Let me know if this helps!