cd backend
python app.py --mode servercd backend
python server.pycd backend
uvicorn server:app --host 0.0.0.0 --port 8000 --reload- API Server: http://localhost:8000
- API Documentation (Swagger UI): http://localhost:8000/docs
- API Documentation (ReDoc): http://localhost:8000/redoc
Check system status
GET /api/healthResponse Example:
{
"status": "healthy",
"model_info": {
"model_name": "buffalo_l",
"device": "cpu",
"embedding_size": 512,
"det_size": [640, 640]
},
"database_info": {
"total_faces": 5,
"total_recognitions": 120,
"threshold": 0.5
}
}Register a new face in the database
POST /api/face/register
Content-Type: multipart/form-dataParameters:
name(string, required): Name of the person to registerfile(file, required): Face image file (JPEG, PNG)
cURL Example:
curl -X POST "http://localhost:8000/api/face/register" \
-F "name=ํ๊ธธ๋" \
-F "file=@/path/to/photo.jpg"Python Example:
import requests
url = "http://localhost:8000/api/face/register"
files = {"file": open("photo.jpg", "rb")}
data = {"name": "ํ๊ธธ๋"}
response = requests.post(url, files=files, data=data)
print(response.json())Response Example (Success):
{
"success": true,
"face_id": "person_20260206_153045",
"name": "ํ๊ธธ๋",
"message": "'ํ๊ธธ๋' ์ผ๊ตด์ด ์ฑ๊ณต์ ์ผ๋ก ๋ฑ๋ก๋์์ต๋๋ค."
}Response Example (Failure - Face Detection Failed):
{
"success": false,
"face_id": null,
"name": null,
"message": "์ด๋ฏธ์ง์์ ์ผ๊ตด์ ๊ฐ์งํ ์ ์์ต๋๋ค. ๋ค๋ฅธ ์ด๋ฏธ์ง๋ฅผ ์๋ํด์ฃผ์ธ์."
}Retrieve all registered face information
GET /api/faces/listcURL Example:
curl -X GET "http://localhost:8000/api/faces/list"Response Example:
{
"total": 3,
"faces": [
{
"face_id": "person_20260206_153045",
"name": "ํ๊ธธ๋",
"registered_at": "2026-02-06T15:30:45.123456",
"last_seen": "2026-02-06T16:20:10.654321",
"recognition_count": 25,
"image_path": "faces/person_20260206_153045.jpg"
},
{
"face_id": "person_20260206_140530",
"name": "๊น์ฒ ์",
"registered_at": "2026-02-06T14:05:30.789012",
"last_seen": null,
"recognition_count": 0,
"image_path": "faces/person_20260206_140530.jpg"
}
]
}Delete a registered face
DELETE /api/face/{face_id}Parameters:
face_id(path parameter, required): Face ID to delete
cURL Example:
curl -X DELETE "http://localhost:8000/api/face/person_20260206_153045"Response Example (Success):
{
"success": true,
"face_id": "person_20260206_153045",
"message": "์ผ๊ตด ID 'person_20260206_153045'๊ฐ ์ฑ๊ณต์ ์ผ๋ก ์ญ์ ๋์์ต๋๋ค."
}Response Example (Failure):
{
"detail": "์ผ๊ตด ID 'invalid_id'๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค."
}Real-time face recognition video stream
GET /api/camera/streamUsage:
<!DOCTYPE html>
<html>
<head>
<title>์ผ๊ตด ์ธ์ ์คํธ๋ฆฌ๋ฐ</title>
</head>
<body>
<h1>์ค์๊ฐ ์ผ๊ตด ์ธ์</h1>
<img src="http://localhost:8000/api/camera/stream"
alt="Video Stream"
width="640"
height="480">
</body>
</html>function VideoStream() {
return (
<div>
<h1>์ค์๊ฐ ์ผ๊ตด ์ธ์</h1>
<img
src="http://localhost:8000/api/camera/stream"
alt="Video Stream"
width={640}
height={480}
/>
</div>
);
}Features:
- Streaming in MJPEG format
- Real-time face detection and recognition
- Registered faces: Green box + name + confidence score
- Unregistered faces: Red box + "Unknown"
# 1. Health check
curl http://localhost:8000/api/health
# 2. Register face (using test image)
curl -X POST "http://localhost:8000/api/face/register" \
-F "name=ํ
์คํธ" \
-F "file=@test_image.jpg"
# 3. Check face list
curl http://localhost:8000/api/faces/list
# 4. Check video stream (in browser)
# http://localhost:8000/api/camera/streamimport requests
import json
# Server address
BASE_URL = "http://localhost:8000"
# 1. Health check
response = requests.get(f"{BASE_URL}/api/health")
print("ํฌ์ค์ฒดํฌ:", json.dumps(response.json(), indent=2, ensure_ascii=False))
# 2. Register face
with open("photo.jpg", "rb") as f:
files = {"file": f}
data = {"name": "ํ๊ธธ๋"}
response = requests.post(f"{BASE_URL}/api/face/register", files=files, data=data)
print("๋ฑ๋ก ๊ฒฐ๊ณผ:", json.dumps(response.json(), indent=2, ensure_ascii=False))
# 3. Retrieve face list
response = requests.get(f"{BASE_URL}/api/faces/list")
faces = response.json()
print(f"๋ฑ๋ก๋ ์ผ๊ตด ์: {faces['total']}")
for face in faces['faces']:
print(f" - {face['name']} (ID: {face['face_id']})")
# 4. Delete face
face_id = "person_20260206_153045"
response = requests.delete(f"{BASE_URL}/api/face/{face_id}")
print("์ญ์ ๊ฒฐ๊ณผ:", json.dumps(response.json(), indent=2, ensure_ascii=False))Solution:
- Check if the camera is connected
- Check if another program is using the camera
- Change camera_id in backend/api/routes.py (default: 0)
Solution:
- Check internet connection
- InsightFace model downloads automatically (~200MB)
- First run may take some time
Solution:
- Add frontend URL to origins list in backend/server.py
- Clear browser cache and retry
Solution:
- Shoot in a well-lit location
- Use frontal face photos
- Use high-resolution images
- Adjust threshold value in backend/models/face_database.py (default: 0.5)
Use GPU acceleration on systems with CUDA installed:
pip uninstall onnxruntime
pip install onnxruntime-gpuAdjust face recognition threshold (backend/models/face_database.py):
# Stricter matching (reduce false positives)
database = FaceDatabase(threshold=0.6)
# More lenient matching (reduce false negatives)
database = FaceDatabase(threshold=0.4)- Auto-generated API Documentation: http://localhost:8000/docs
- GitHub Repository: [Project Link]
- Issue Reporting: GitHub Issues
Written: 2026-02-06 Version: 1.0.0