This project is a Python script that utilizes the MediaPipe library for face detection in real-time video streams. It captures video from the default camera, detects faces in each frame, and displays the processed video with bounding boxes around the detected faces.
- Real-time face detection using the MediaPipe library
- Draws bounding boxes around detected faces
- Displays the confidence score for each detected face
- Counts the number of faces detected in each frame
- Computes and displays the frames per second (FPS)
- Applies bilateral filtering for smoothing the output video
- Python 3.x
- NumPy
- OpenCV (cv2)
- MediaPipe
-
Clone the repository:
git clone https://github.com/yashshah035/Face-Counting.git
-
Install the required dependencies:
pip install numpy opencv-python mediapipe
-
Navigate to the project directory:
cd Face-Counting
-
Run the main Python file:
python FaceCounter.py
-
The script will open a window displaying the video feed from your default camera. Detected faces will be highlighted with bounding boxes and confidence scores.
-
Press 'q' to quit the application.
The provided code performs the following steps:
- Imports the necessary libraries: NumPy, time, OpenCV (cv2), and MediaPipe.
- Initializes the MediaPipe Face Detection model with a detection confidence threshold of 0.4.
- Defines a
detector
function that takes a video frame as input, detects faces, and draws bounding boxes and confidence scores on the frame. - Opens the default camera using
cv2.VideoCapture(0)
and sets the resolution to 1980x1080 pixels. - Enters a loop that reads frames from the camera, passes them to the
detector
function, computes the FPS, and displays the processed frame with face detections. - Applies bilateral filtering for smoothing the output video.
- Displays the number of faces detected in the current frame.
- Continues the loop until the 'q' key is pressed, then releases the camera and closes all windows.
Contributions are welcome! If you find any bugs or have suggestions for improvements, feel free to open an issue or create a pull request.