This project provides an API for image-based registration and recognition using the InsightFace library. It allows users to register images with associated names and recognize images against a database of registered images.
face-recog-api
├── src
│ ├── api
│ │ ├── main.py # Entry point for the FastAPI application
│ │ ├── routers
│ │ │ ├── register.py # API endpoint for registering images
│ │ │ └── recognize.py # API endpoint for recognizing images
│ │ └── schemas
│ │ └── index.py # Pydantic models for request and response schemas
│ ├── face_recog
│ │ ├── __init__.py # Package initialization
│ │ ├── register.py # Logic for registering images
│ │ ├── recognize.py # Logic for recognizing images
│ │ └── cli.py # Command-line interface for image operations
├── tests
│ └── test_api.py # Unit tests for API endpoints
├── Dockerfile # Instructions to build the Docker image
├── docker-compose.yml # Service orchestration for the application
├── .dockerignore # Files to ignore when building the Docker image
├── requirements.txt # Python dependencies for the project
└── README.md # Project documentation
-
Clone the repository:
git clone <repository-url> cd face-recog-api -
Build the Docker image:
docker build -t face-recog-api . -
Run the application using Docker Compose:
docker compose up -
Access the API: The API will be available at
http://localhost:8000. You can use tools like Postman or curl to interact with the endpoints.
- Endpoint:
POST /register - Request Body:
{ "image": "base64_encoded_image_string", "name": "person_name" } - Response:
- Success:
{"message": "Registered successfully", "id": "unique_id"} - Error:
{"error": "Error message"}
- Success:
- Endpoint:
POST /recognize - Request Body:
{ "image": "base64_encoded_image_string", "topk": 1, "threshold": 0.5 } - Response:
- Success:
{"matches": [{"name": "person_name", "id": "unique_id", "score": score}]}or{"matches": []} - Error:
{"error": "Error message"}
- Success:
To run the tests, use the following command:
pytest tests/test_api.py
This project is licensed under the MIT License. See the LICENSE file for details.