A lightweight face detection API built with Flask and OpenCV's DNN face detector. It accepts an image upload and reports whether a face was detected and how many faces were found.
- REST API for face detection
- OpenCV DNN SSD face detection model
- Docker and Docker Compose support
- JSON responses with face presence and count
- Python 3.12 or newer
- Docker and Docker Compose (optional)
The required model files are included in the models/ directory.
docker compose up --buildThe API will be available at:
http://localhost:5000
To stop the service:
docker compose downCreate and activate a virtual environment, then install the dependencies:
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtStart the API:
python app.pyThe server listens on 0.0.0.0:5000.
Upload an image using the image form field.
curl -X POST \
-F "image=@path/to/image.jpg" \
http://localhost:5000/detect_faceSuccessful response:
{
"has_face": true,
"face_count": 1
}The detector accepts detections with confidence greater than 0.6.
Missing image field:
{
"error": "image file is required"
}Invalid image data:
{
"error": "invalid image"
}Both errors return HTTP status 400.
.
├── app.py
├── docker-compose.yml
├── Dockerfile
├── requirements.txt
└── models/
├── deploy.prototxt
└── res10_300x300_ssd_iter_140000.caffemodel
Add your preferred license before publishing this repository.