A beginner-friendly computer vision project that detects cat faces in images and videos using OpenCV and Haar Cascades.
- Overview
- Features
- Installation
- Usage
- Project Structure
- How It Works
- Results
- Future Improvements
- Contributing
- License
This project demonstrates real-time cat face detection using computer vision techniques. Built as a beginner-friendly introduction to OpenCV, it can detect cat faces in:
- Static images
- Video files
- Live webcam feeds
Perfect for learning the fundamentals of object detection and creating fun content with your pets!
- β Real-time detection in video streams
- β Batch processing of images and videos
- β Webcam support for live demonstrations
- β Automatic video saving with detections
- β Detection statistics (frames processed, cats detected)
- β Easy-to-use command-line interface
- Python 3.8 or higher
- pip package manager
git clone https://github.com/Ph0enix22/cat-detector.git
cd cat-detector# Windows
python -m venv venv
venv\Scripts\activate
# Mac/Linux
python3 -m venv venv
source venv/bin/activatepip install -r requirements.txtDownload the haarcascade_frontalcatface.xml file from the OpenCV GitHub repository and place it in the project root directory.
python cat_detector.py --input path/to/cat_image.jpg --mode imagepython cat_detector.py --input path/to/cat_video.mp4 --mode videopython cat_detector.py --input 0 --mode video# Custom output directory
python cat_detector.py --input video.mp4 --mode video --output my_outputs
# Use different cascade file
python cat_detector.py --input video.mp4 --cascade custom_cascade.xml
# Preview only (don't save output)
python cat_detector.py --input 0 --mode video --no-save| Argument | Short | Description | Default |
|---|---|---|---|
--input |
-i |
Input image/video path, or 0 for webcam | Required |
--mode |
-m |
Detection mode: 'image' or 'video' | video |
--cascade |
-c |
Path to Haar cascade XML file | haarcascade_frontalcatface.xml |
--output |
-o |
Output directory | outputs |
--no-save |
- | Don't save output (preview only) | False |
cat-detector/
β
βββ cat_detector.py # Main detection script
βββ haarcascade_frontalcatface.xml # Haar cascade model
βββ requirements.txt # Python dependencies
βββ README.md # Project documentation
βββ .gitignore # Git ignore rules
βββ LICENSE # Project license
β
βββ videos/ # Input videos (cat footage)
β βββ cat_video1.mp4
β βββ kitten_video1.mp4
β
βββ outputs/ # Detected outputs (images + videos)
β βββ detected_20251227_233739.mp4
β βββ detected_cat1.jpeg
β
βββ screenshots/ # Original cat images before detection
β βββ cat1.jpeg
β βββ cat2.jpeg
βββ demo/ # Demo assets (GIFs, live detection screenshots, screen recordings)
βββ demo_detection.gif
βββ demo_recording.mp4
This project uses Haar Cascade Classifiers, a machine learning-based approach for object detection:
- Pre-trained on thousands of positive (cat faces) and negative (non-cat) images
- Uses multiple stages of weak classifiers to identify features
- Fast and efficient for real-time detection
- Works best with frontal face views
Input (Image/Video)
β
Convert to Grayscale
β
Apply Haar Cascade Detector
β
Find Regions of Interest (ROI)
β
Draw Bounding Boxes
β
Output Annotated Image/Video
- scaleFactor (1.3): How much the image size is reduced at each scale
- minNeighbors (10): How many neighbors each candidate rectangle should have
- minSize (75x75): Minimum object size to detect
Total frames processed: 450
Total cat detections: 412
Average detections per frame: 0.92
Detection accuracy: ~90% on frontal faces
- Processing Speed: ~30 FPS on modern laptops
- Best Results: Well-lit environments with frontal face views
- Limitations: Reduced accuracy with side profiles or poor lighting
- Add size-based classification (cat vs kitten)
- Implement confidence scores
- Create a simple GUI with Tkinter
- Add support for multiple cascade types
- Upgrade to YOLO for better accuracy
- Train custom model on specific pets
- Deploy as web app with Streamlit
- Add pet activity tracking over time
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- OpenCV for the computer vision library
- OpenCV Haar Cascade models for the pre-trained classifier
- My cats, for patiently (and not so patiently) posing for the camera
- My siblings, for helping with recordings, testing, and feedback
SMJ
- GitHub: Ph0enix22
- LinkedIn: Syeda Midhath Javeria
- Email: [email protected]
New to computer vision? Check these out:
Made with β€οΈ by SMJ (for beginners in computer vision)

