This project demonstrates real-time face detection using OpenCV and MediaPipe libraries. The application captures video from the laptop's camera, detects faces, and draws bounding boxes around detected faces. Additionally, it displays the confidence score for each detection and the total number of faces detected in the current frame.
- Real-time face detection using the laptop camera.
- Bounding boxes drawn around detected faces.
- Confidence scores displayed for each detection.
- Total number of faces displayed on the screen.
- Uses MediaPipe for face detection and OpenCV for video capture and processing.
Before running the project, ensure you have the following installed:
- Python 3.x
- OpenCV (
opencv-python
) - MediaPipe (
mediapipe
)
-
Clone the repository or download the project files:
git clone https://github.com/ashwindalvi300/Face-Detection-using-Laptop-Camera.git
-
Navigate to the project directory:
cd Face-Detection-using-Laptop-Camera
-
Install the required libraries using
pip
:pip install opencv-python pip install mediapipe
-
Run the Python script to start face detection using your laptop's camera:
python face_detection.py
-
The program will open a window showing the camera feed with bounding boxes around detected faces, the detection confidence, and the total number of faces in the frame.
-
To stop the face detection, press the 'q' key.
- OpenCV: Used for capturing video from the camera and for image processing (drawing rectangles, putting text, etc.).
- MediaPipe: Provides a pre-trained face detection model. It processes each frame to detect faces and returns bounding box coordinates and confidence scores.
- Video Capture: The camera feed is captured using
cv2.VideoCapture(0)
, where0
specifies the default camera. - Face Detection: The
MediaPipe
face detection model is initialized with a confidence threshold of 60%. Detected faces are outlined with red rectangles, and their confidence scores are displayed. - Real-time Display: The faces detected are displayed in real-time, with the ability to press 'q' to exit the program.
- Confidence Threshold: You can modify the face detection confidence threshold by changing the parameter
FaceDetection(0.6)
in the script to a different value (0 to 1). - Camera Source: If you have multiple cameras, change
cv2.VideoCapture(0)
tocv2.VideoCapture(1)
(or other numbers) to use a different camera. - Frame Rate: Adjust the frame processing speed by modifying the
cv2.waitKey(1)
delay value.