Count number of Faces using Python – OpenCV
Prerequisites: Face detection using dlib and openCV
In this article, we will use image processing to detect and count the number of faces. We are not supposed to get all the features of the face. Instead, the objective is to obtain the bounding box through some methods i.e. coordinates of the face in the image, depending on different areas covered by the number of the coordinates, number faces that will be computed.
- OpenCV library in python is a computer vision library, mostly used for image processing, video processing, and analysis, facial recognition and detection, etc.
- Dlib library in python contains the pre-trained facial landmark detector, that is used to detect the (x, y) coordinates that map to facial structures on the face.
- Numpy is a general-purpose array-processing package. It provides a high-performance multidimensional array object and tools for working with these arrays.
Below is the step-wise approach to Count the Number of faces:
Step 1: Import required libraries.
Step 2: Open the default camera to capture faces and use the dlib library to get coordinates.
Step 3: Count the number of faces.
- Capture the frames continuously.
- Convert the frames to grayscale(not necessary).
- Take an iterator i and initialize it to zero.
- Each time you get the coordinates to the face structure in the frame, increment the iterator by 1.
- Plot the box around each detected face along with its face count.
Step 4: Terminate the loop.
Step 5: Clear windows.
Below is the complete program of the above approach:
My Personal Notes arrow_drop_up
Please Login to comment...