- Baby Smile Detector πΆπ
Project page: https://huggingface.co/spaces/Anirudh1950/Baby-Smile-Detection
Baby Smile Detector πΆπ
A real-time baby smile detection system using ONNX runtime and OpenCV. This application can detect smiles in live webcam feed, images, or pre-recorded videos. Perfect for capturing those precious smiling moments of your baby!
Features
- π Real-time face and smile detection
- π₯ Multiple input sources (webcam, image, video)
- πΎ Save detected smiles automatically
- ποΈ Adjustable confidence threshold
- π Sound alerts on smile detection
- ποΈ Save processed videos
- π₯οΈ Toggle display options (FPS, confidence scores)
- πΌοΈ View saved smile captures
π Installation
Prerequisites
- Python 3.7 or higher
- Webcam (for live detection)
- Windows/macOS/Linux
Quick Start
Clone this repository:
git clone https://github.com/yourusername/baby-smile-detector.git cd baby-smile-detectorCreate and activate a virtual environment (recommended):
python -m venv venv .\venv\Scripts\activate # Windows # OR source venv/bin/activate # Linux/MacInstall the required dependencies:
pip install -r requirements.txtDownload the pre-trained model (if not included):
# Place the ONNX model file in the project directory # Rename it to 'best_face.onnx' or specify the path using --model
π― Usage Examples
π₯ Live Webcam Detection
Detect smiles using your default webcam:
python baby_smile_detector.py --show-fps --show-confidence --sound
π· Process a Single Image
Analyze a photo and save the result:
python baby_smile_detector.py --input test_image.jpg --output results/
ποΈ Process a Video File
Process a video and save the output:
python baby_smile_detector.py --input input_video.mp4 --output-video output.mp4 --no-display
πΌοΈ View Saved Smile Captures
Browse through previously detected smiles:
python baby_smile_detector.py --view-saved
πββοΈ Run in Background Mode
Process without display (useful for servers):
python baby_smile_detector.py --no-display --no-save --input video.mp4
Advanced Options
# Run with custom settings
python baby_smile_detector.py \
--input input.mp4 \
--output-video output.mp4 \
--threshold 0.7 \
--show-fps \
--show-confidence \
--skip-frames 1
Command Line Arguments
| Argument | Description | Default |
|---|---|---|
--input |
Path to input image or video file | None (use webcam) |
--camera |
Camera device index | 0 |
--model |
Path to ONNX model | 'best_face.onnx' |
--threshold |
Confidence threshold (0-1) | 0.6 |
--output |
Output directory for saved smiles | 'smile_captures' |
--no-save |
Disable saving detected smiles | False |
--output-video |
Save output as video file | None |
--no-display |
Run without display | False |
--show-fps |
Show FPS counter | False |
--show-confidence |
Show confidence scores | False |
--sound |
Enable sound alerts | False |
--volume |
Sound volume (0.0-1.0) | 1.0 |
--skip-frames |
Skip N frames between processing | 0 |
--view-saved |
View previously saved captures | False |
Controls (When Display is Enabled)
q- Quit the applications- Save current framet- Toggle sound alertsβ/β- Increase/Decrease confidence thresholdf- Toggle FPS displayc- Toggle confidence display
Viewing Saved Captures
Use the --view-saved option to browse through all saved smile captures. In the viewer:
βord- Next imageβora- Previous imageqorESC- Quit viewer
π Requirements
The application requires the following Python packages (automatically installed via requirements.txt):
opencv-python>=4.5.0- For image/video processingnumpy>=1.19.0- For numerical operationsonnxruntime>=1.8.0- For running the ONNX modelPillow>=8.0.0- For image processingsounddevice>=0.4.0- For audio alerts (optional)tqdm>=4.50.0- For progress bars during video processing
π οΈ Installation Troubleshooting
Common Issues
Webcam not detected:
- Ensure no other application is using the webcam
- Try a different camera index:
--camera 1
Model loading issues:
- Verify the ONNX model is in the correct location
- Check model compatibility with your ONNX Runtime version
Missing dependencies:
# If installation fails, try upgrading pip first pip install --upgrade pip # Then install requirements again pip install -r requirements.txt
π‘ Tips for Best Results
πΈ Image/Video Quality
- Use good lighting on the face
- Position the camera at eye level
- Ensure the face is clearly visible
- Ideal distance: 1-2 meters from the camera
βοΈ Performance Tuning
For better accuracy:
- Lower the threshold (e.g.,
--threshold 0.5) - Ensure good lighting conditions
- Lower the threshold (e.g.,
For better performance:
- Increase
--skip-framesvalue - Use
--no-displayfor faster processing - Lower the resolution of input video
- Increase
π― Model Information
- Input size: 640x480 pixels (automatically resized)
- Output: Bounding box coordinates and confidence scores
- Model format: ONNX (Open Neural Network Exchange)
π€ Contributing
Contributions are welcome! Here's how you can help:
- Report bugs or request features by opening an issue
- Submit pull requests with improvements
- Share your trained models
- Improve documentation
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π Acknowledgments
- Thanks to the OpenCV and ONNX Runtime communities
- Pre-trained models from Face Detection RetinaFace
- Inspired by real-world baby monitoring applications
License
This project is licensed under the MIT License - see the LICENSE file for details.
Source code: https://github.com/rudzz1950/Baby-Smile-Detection
Run locally
pip install -r requirements.txt
python app.py
app.py is a Gradio app; the original project scripts are unchanged alongside it.
