A Python-based face detection system using OpenCV and Haar Cascades for real-time face detection and dataset creation.
- Real-time face detection using webcam
- Automatic face dataset creation
- Face cropping and resizing
- Image storage in organized directories
- Python 3.x
- OpenCV (cv2)
- Webcam/Camera access
- Install required dependencies:
pip install opencv-python- Ensure your camera/webcam is connected and accessible
face-detection/
├── Day5_Code/
│ ├── dataset/
│ │ └── champ/ # Captured face images
│ ├── FaceDetection.py # Main face detection script
│ ├── faceDataset.py # Dataset creation script
│ └── haarcascade_frontalface_default.xml # Haar cascade classifier
└── README.md
Run the main face detection script:
python Day5_Code/FaceDetection.pyRun the dataset creation script:
python Day5_Code/faceDataset.py- Camera Initialization: Opens webcam feed
- Face Detection: Uses Haar Cascade classifier to detect faces
- Image Processing: Converts to grayscale and crops detected faces
- Storage: Saves resized face images (130x100 pixels) to dataset folder
- Real-time Display: Shows live feed with face detection rectangles
- ESC key: Exit the application
- Automatic capture: Captures 30 face images automatically
- Face images are saved in
dataset/champ/directory - Images are numbered sequentially (1.jpg to 30.jpg)
- Each image is resized to 130x100 pixels in grayscale
- Camera not opening: Check camera permissions and ensure no other application is using the camera
- No faces detected: Ensure proper lighting and face positioning
- Import errors: Verify OpenCV installation with
pip install opencv-python
- The system captures 30 images by default
- Face detection works best with good lighting conditions
- Ensure face is clearly visible and properly positioned in the camera frame