This Python script utilizes OpenCV to perform real-time face detection and blurring in video streams from a webcam. It detects faces in the video frames using a pre-trained Haar Cascade classifier and applies Gaussian blur to the detected faces while keeping the rest of the frame unchanged.
- Real-time Face Detection: Detects faces in the video stream from the webcam in real-time.
- Face Blurring: Applies Gaussian blur to the detected faces to anonymize them while preserving the rest of the frame.
- Video Capture: Utilizes OpenCV's
VideoCapturemodule to access the video stream from the default camera. - User Interaction: The script exits when the Enter key is pressed, allowing for user-controlled termination.
-
Install OpenCV: Install OpenCV library using pip if not already installed.
pip install opencv-python
-
Download Haar Cascade Classifier: Ensure that you have the Haar Cascade XML file (
haarcascade_frontalface_default.xml) for face detection. You can find it in thedata/haarcascadesdirectory of your OpenCV installation. -
Run the Script: Execute the Python script provided (
face_blurring.pyor any preferred filename) using a Python interpreter.python face_blurring.py
-
Terminate the Script: Press the Enter key to exit the script and close the video stream window.
- OpenCV: Open Source Computer Vision Library for image and video processing.
- You may need to adjust the parameters of the
detectMultiScalefunction (e.g.,scaleFactor,minNeighbors,minSize) based on the environmental conditions for optimal face detection performance. - Ensure that your webcam is correctly configured and accessible by OpenCV.
This project is licensed under the MIT License. See the LICENSE file for details.