Seeta6 Face Recognition System API Documentation
For Seeta6WindowsDemo (C++ detection services) and face_server (Flask deployment server)
Table of Contents
- 1 System Overview and Architecture
- 2 One-click Startup and Deployment
- 3 Deployment Server API (Flask :5000)
- 4 Real-time Enrollment Detection API (C++ :8765, for realtime.html)
- 5 Photo Enrollment Detection API (C++ :8766, for snapshot.html)
- 6 Enrollment Timing Control
- 7 Pose Checking and Adjustment
- 8 Quality Assessment and Thresholds
- 9 C++ Model File Deployment
- 10 Appendix: Request and Response Examples
1 System Overview and Architecture
The system is used for web-based face capture and enrollment plus device authorization management. It consists of a deployment server, two C++ detection services and a reverse proxy, and all face photos are archived to Qiniu Cloud Storage.
1.1 System Components
- Deployment server (server5000.py, Python Flask, port 5000): activation code verification, device management, face photo upload to Qiniu, cloud photo listing, and the web admin console.
- Real-time enrollment detection service (face_server.exe, C++, port 8765): used by realtime.html, detects faces frame by frame and returns the detection box, landmarks, quality, pose, age, gender, eye state, etc.
- Photo enrollment detection service (face_server_photo.exe, C++, port 8766): used by snapshot.html, evaluates occlusion, pose and quality for a single photo and returns the result.
- Reverse proxy (caddy.exe, port 443): unified HTTPS entry point, forwards requests to the services above by path, and hosts static pages such as realtime.html and snapshot.html.
- Data dependencies: Qiniu Cloud Storage (face photos), SQLite (seeta6.db, devices and activation codes), Seeta6 model library and DLLs.
1.2 Architecture Diagram
Seeta6 face recognition system architecture
Figure 1 Seeta6 face recognition system architecture
1.3 Services and Ports
| Service | Tech stack | Port | Public path | Main endpoints | Start command |
|---|---|---|---|---|---|
| server5000.py | Python Flask | 5000 | /api/* | device_verify_code, cloud_images, upload_face, code_images, admin/* | python server5000.py |
| face_server.exe | C++ httplib | 8765 | /detect, /set_models | Frame detection, model toggles | face_server.exe |
| face_server_photo.exe | C++ httplib | 8766 | /check | Single photo evaluation | face_server_photo.exe |
| caddy.exe | Caddy (Go) | 443 | All | Reverse proxy + static files | caddy run --config Caddyfile |
Table 1 Services and ports
1.4 Front-end Enrollment Entry Pages
Access the following paths after deployment (the actual domain or IP is configured in the Caddyfile):
- Real-time enrollment page:
https://<YOUR_SERVER>/realtime.html - Photo enrollment page:
https://<YOUR_SERVER>/snapshot.html - Admin console:
https://<YOUR_SERVER>/(user YOUR_ADMIN_USER / password YOUR_ADMIN_PASSWORD)
After opening an enrollment page, enter an activation code first; activation codes are generated in the admin console.
2 One-click Startup and Deployment
Double-click start_all.bat to start four processes in order: face_server.exe (8765) → face_server_photo.exe (8766) → python server5000.py (5000) → caddy.exe (443).
Python dependencies: pip install flask qiniu flask-cors. The C++ services and Caddy are build artifacts and require no extra installation.
If the detection service is not running, the enrollment page shows "Detection service is not running, please start face_server.exe first".
3 Deployment Server API (Flask :5000)
All endpoints return JSON: code=0 means success, code=1 means a business error, and code=-1 means a system exception. CORS is enabled, so cross-origin calls are supported.
3.1 Activation Code Verification POST /api/device_verify_code
Request body (JSON):
{"device_id": "web-xxxxxxxxxxxxxxx", "activation_code": "YOUR_ACTIVATION_CODE"}device_idis generated by the front end and stored in browser localStorage; theweb-prefix denotes a web enrollment device and theandroid_prefix an Android device.- The web device binding limit is fixed at 30 (
WEB_MAX_DEVICESin server5000.py); Android devices are counted against the activation code's ownmax_deviceslimit. - An activation code can have an expiry date
expire_time(YYYY-MM-DD); verification fails after it expires.
Response:
{"code": 0, "msg": "验证成功"}Failure examples:
{"code": 1, "msg": "激活码无效"}
{"code": 1, "msg": "激活码已达绑定上限(30)"}
{"code": 1, "msg": "激活码已过期"}3.2 Cloud Photo List GET /api/cloud_images
GET /api/cloud_images?device_id=web-xxx&folder=facesThe device must be activated. Each call refreshes the device's last-active time and IP. folder defaults to faces and lists all files under that prefix in Qiniu.
{"code": 0, "categories": {"all": [{"key": "faces/1.jpg", "filename": "1.jpg", "url": "http://<YOUR_CDN_DOMAIN>/faces/1.jpg"}]}}3.3 Upload Face Photo POST /api/upload_face
Request body (JSON):
{"device_id": "web-xxx", "activation_code": "YOUR_ACTIVATION_CODE", "name": "张三", "image": "data:image/jpeg;base64,..."}imageis base64 (an optional data URL header is allowed); a single photo must not exceed 5 MB.- File name rule:
faces/{activation code}/{name}_{HHMMSS}.jpg; illegal characters in the name are replaced with underscores and the name is capped at 32 characters. - The device must be activated and the activation code must match the bound one.
Response:
{"code": 0, "msg": "上传成功", "key": "faces/YOUR_ACTIVATION_CODE/张三_143025.jpg", "url": "http://<YOUR_CDN_DOMAIN>/faces/YOUR_ACTIVATION_CODE/张三_143025.jpg"}3.4 List Photos by Activation Code GET /api/code_images
GET /api/code_images?activation_code=YOUR_ACTIVATION_CODELists all photos under the faces/{activation code}/ prefix in reverse upload order (newest first).
{"code": 0, "total": 2, "data": [{"key": "faces/YOUR_ACTIVATION_CODE/张三_143025.jpg", "filename": "张三_143025.jpg", "url": "http://...", "put_time": 17700000000000000}]}3.5 Admin API (Login Required)
Login: POST /login with body {"username": "YOUR_ADMIN_USER", "password": "YOUR_ADMIN_PASSWORD"}; on success it returns {"code": 0, "msg": "登录成功"} and writes the session. Accessing /api/admin/* without login returns 401.
| Endpoint | Method | Description | Parameters |
|---|---|---|---|
| /api/admin/stats | GET | Device / activation code statistics | — |
| /api/admin/code_list | GET | Activation code list (with bound counts) | — |
| /api/admin/code_add | POST | Add an activation code | code, note, max_devices, expire_time |
| /api/admin/code_delete | POST | Delete an activation code and unbind its devices | code |
| /api/admin/device_list | GET | Device list (filter by keyword / code) | kw, code |
| /api/admin/device_delete | POST | Delete a device | device_id |
| /api/admin/device_unbind | POST | Unbind a device | device_id |
| /api/admin/cleanup_web | POST | Manually clean up all web devices | — |
Table 2 Admin API
Admin pages: GET / (admin home), /login, /logout. A background thread also cleans up web devices automatically once per hour.
4 Real-time Enrollment Detection API (C++ :8765, for realtime.html)
4.1 Frame Detection POST /detect
Request body (JSON):
{"frame": "data:image/jpeg;base64,..."}Response (JSON):
{"faces": [{"x": 120, "y": 80, "w": 200, "h": 200, "score": 0.97, "quality": 0.85, "yaw": 2.1, "pitch": -1.5, "roll": 0.3, "q_light": -1, "q_blur": -1, "q_noise": -1, "occluded_face": 0, "occluded_total": 0, "age": 28, "gender": 1, "eye_left": 1, "eye_right": 1, "pts5": [100,90,140,92,120,130,105,155,140,155]}], "img_w": 640, "img_h": 480}| Field | Type | Description |
|---|---|---|
| x, y, w, h | int | Top-left corner, width and height of the face box (pixels) |
| score | float | Detection confidence (0–1) |
| quality | float | Quality score (0–1), see Chapter 8 for the formula |
| yaw / pitch / roll | float | Head pose angles (degrees) |
| q_light | int | Lighting: 1=too dark, -1=normal or not evaluated |
| q_blur | int | Blur: 1=blurred, -1=sharp or not evaluated |
| q_noise | int | Noise: 0=too noisy, -1=normal or not evaluated |
| occluded_face | int | Number of occluded points in the eye-nose region (out of 68-point indices 27–47) |
| occluded_total | int | Total number of occluded points among the 68 face points |
| age | int | Age (-1 means disabled or prediction failed) |
| gender | int | Gender (0=male, 1=female, -1 not enabled) |
| eye_left / eye_right | int | Eye state (0=closed, 1=open, 2=random, 3=unknown) |
| pts5 | float[] | Flat array of 5 landmark coordinates [x0,y0,...,x4,y4] |
Table 3 /detect response fields
4.2 Model Toggles POST /set_models
Request body (JSON); keys not sent keep their current state:
{"detector": true, "landmarker5": true, "landmarker68": true, "quality": true, "pose": true, "age": false, "gender": false, "eye": false}Response:
{"ok": true}Default toggles are defined in face_server.cpp: age, gender and eye are off by default and the rest are on. When detector is off, no detection results are returned.
5 Photo Enrollment Detection API (C++ :8766, for snapshot.html)
5.1 Photo Detection POST /check
Request body (JSON):
{"image": "data:image/jpeg;base64,..."}Response (passed):
{"ok": true, "reason": "", "quality": 0.88, "yaw": 3.2, "pitch": -2.1, "roll": 1.0, "occluded": 0, "face": {"x": 120, "y": 80, "w": 200, "h": 200}}Response (failed):
{"ok": false, "reason": "请正对摄像头", "quality": 0.50, "yaw": 25.0, "pitch": -2.0, "roll": 1.0, "occluded": 0, "face": {"x": 120, "y": 80, "w": 200, "h": 200}}reason values: 未检测到人脸、请勿遮挡人脸、请正对摄像头、光线偏暗、图像模糊、噪声过大、图像质量不合格. The checks run in the order occlusion → pose → quality, only the largest face in the frame is used, and the thresholds match the front end (see Chapters 7 and 8).
6 Enrollment Timing Control
6.1 Real-time Mode: Auto-enroll after 1.3 s of Passing
In realtime.html, once the face meets all conditions (pose OK, quality OK, no occlusion, eyes open) continuously for 1.3 s, the current frame is frozen automatically and a name input box appears.
Where to adjust: the configuration block at the top of realtime.html:
const HOLD_MS = 1300; // 保持时长(毫秒),1.3 秒Logic: checkTrigger() starts timing (okStartTime) when all conditions pass and triggers enrollment after HOLD_MS milliseconds; any failing condition resets the timer. Refresh the page after changing it. A larger value requires a longer hold (stricter); a smaller value causes false triggers more easily.
6.2 Photo Mode: Manual Click Trigger
snapshot.html has no automatic timer. The operator clicks "拍照并检测"; after a single photo passes, they enter a name and upload it. There is no hold-time parameter.
7 Pose Checking and Adjustment
Pass condition: |yaw|, |pitch| and |roll| all not greater than 10 degrees counts as a passing pose; otherwise "请正对摄像头" is shown. Pose angles are output by pose_estimation.csta (SeetaPoseEstimation600.dll).
Where to adjust (both places must be changed together):
// 实时版前端 realtime.html 顶部配置区
const POSE_LIMIT = 10; // 姿态角上限(度)
// 拍照版服务端 face_server_photo.cpp 第 44 行(改后需重新编译)
static const float POSE_LIMIT = 10.0f; // 姿态角上限(度)In the real-time version, POSE_LIMIT is used for checking and for generating guidance text in drawResult(), checkTrigger() and updatePreview(); in the photo version it is checked in process_single(). For a standard indoor scene keep 10 degrees; if the lighting or device angle is poor, you may relax it to 15–20 degrees, but that lowers the frontal-face quality of the captured photos, and exceeding 20 degrees is not recommended.
8 Quality Assessment and Thresholds
8.1 Quality Score Formula
The C++ side uses QualityOfLBN (quality_lbn.csta) to output three metrics — lighting light, blur blur and noise noise — and computes the quality score as follows:
q = 1.0 - 0.33 × (light==1 偏暗) - 0.33 × (blur==1 模糊) - 0.34 × (noise==0 噪声大),下限 0That is: too dark deducts 0.33, blur deducts 0.33, too much noise deducts 0.34, and a fully normal image scores 1.0.
8.2 Pass Threshold
quality ≥ 0.66 counts as passing. Where to adjust (both places must be changed together):
// 实时版前端 realtime.html 顶部配置区
const QUALITY_THRESHOLD = 0.66; // 质量分阈值
// 拍照版服务端 face_server_photo.cpp 第 45 行(改后需重新编译)
static const float QUALITY_THRESHOLD = 0.66f; // 质量分阈值8.3 Other Checks
- Occlusion: the number of occluded points in the 68-point eye-nose region (indices 27–47) must be ≤ 1 to pass.
OCCLUDED_FACE_LIMIT=1in realtime.html andOCCLUDED_FACE_LIMIT=1in face_server_photo.cpp must be adjusted together. - Eyes open: eye_left and eye_right must both be non-zero (0=closed) to pass; both the real-time and photo front ends check this.
- Mapping between failure messages and metrics: q_light=1 shows "光线偏暗", q_blur=1 shows "图像模糊", q_noise=0 shows "噪声过大"; see
drawResult()andupdatePreview()in the front end.
9 C++ Model File Deployment
9.1 Model Directory
The model directory constant is defined at line 44 of face_server.cpp and line 39 of face_server_photo.cpp:
static const std::string MODEL_DIR = "C:/path/to/models/";Deployment: put the model files in that directory. If the directory does not exist, model initialization fails when the process starts. Recompile after changing the directory path or model files.
9.2 Model File List
| Model file | Size | face_server.exe (real-time) | face_server_photo.exe (photo) |
|---|---|---|---|
| face_detector.csta | 3.9 MB | Required | Required |
| face_landmarker_pts5.csta | 0.4 MB | Required | Required |
| face_landmarker_pts68.csta | 2.4 MB | Required | Required |
| quality_lbn.csta | 0.9 MB | Required | Required |
| pose_estimation.csta | 1.9 MB | Required | Required |
| age_predictor.csta | 31.4 MB | Required | — |
| gender_predictor.csta | 0.9 MB | Required | — |
| eye_state.csta | 2.8 MB | Required | — |
Table 4 Model files required by the C++ services (measured sizes)
Extended models (not needed for this enrollment flow; used for recognition / liveness scenarios): face_recognizer.csta, face_recognizer_mask.csta, face_landmarker_mask_pts5.csta, mask_detector.csta, fas_first.csta, fas_second.csta.
9.3 Runtime DLLs
| DLL | Purpose |
|---|---|
| SeetaFaceDetector600.dll | Face detection |
| SeetaFaceLandmarker600.dll | 5-point / 68-point landmarks |
| SeetaQualityAssessor300.dll | Image quality assessment |
| SeetaPoseEstimation600.dll | Head pose estimation |
| SeetaAgePredictor600.dll | Age prediction (real-time) |
| SeetaGenderPredictor600.dll | Gender prediction (real-time) |
| SeetaEyeStateDetector200.dll | Eye state detection (real-time) |
| SeetaAuthorize.dll / SeetaAuthorized.dll | SDK license files; missing files cause model initialization to fail |
| tennis.dll | SDK runtime dependency |
Table 5 Runtime DLLs (all in the same directory as the exe)
Put the DLLs and the exe in the same directory (Seeta6WindowsDemo). After compiling, build.bat automatically copies any missing DLLs from the SDK's lib\x64.
9.4 Build Instructions
Build environment: Visual Studio 2022 Build Tools (build.bat calls vcvars64.bat to initialize). SDK path constant: SEETA_ROOT=C:\path\to\seeta_sdk (containing include and lib\x64).
- Real-time version: run build.bat to compile face_server.cpp into face_server.exe, linking SeetaFaceDetector600.lib, SeetaFaceLandmarker600.lib, SeetaQualityAssessor300.lib, SeetaPoseEstimation600.lib, SeetaAgePredictor600.lib, SeetaGenderPredictor600.lib and SeetaEyeStateDetector200.lib.
- Photo version: run build_photo.bat to compile face_server_photo.cpp into face_server_photo.exe, linking only the detection, landmark, quality and pose libraries.
- You must recompile after changing source constants such as the model directory or decision thresholds.
9.5 Run and Integration Test
After startup, the C++ service console prints "[OK] 所有模型加载完成". Open realtime.html in a browser and enter an activation code; a green face box indicates the integration works. If the detection service is not running, the page shows "Detection service is not running, please start face_server.exe first".
10 Appendix: Request and Response Examples
The examples below use the placeholder address http://<YOUR_SERVER> (forwarded by Caddy); the actual deployment environment prevails.
10.1 Activation Code Verification
curl -X POST http://<YOUR_SERVER>/api/device_verify_code \
-H "Content-Type: application/json" \
-d '{"device_id": "web-demo001", "activation_code": "YOUR_ACTIVATION_CODE"}'
响应:{"code": 0, "msg": "验证成功"}10.2 Real-time Frame Detection
curl -X POST http://<YOUR_SERVER>/detect \
-H "Content-Type: application/json" \
-d '{"frame": "data:image/jpeg;base64,..."}'
响应(截断):{"faces": [{"x": 120, "y": 80, "w": 200, "h": 200, "score": 0.97, ...}], "img_w": 640, "img_h": 480}10.3 Photo Evaluation
curl -X POST http://<YOUR_SERVER>/check \
-H "Content-Type: application/json" \
-d '{"image": "data:image/jpeg;base64,..."}'
响应:{"ok": true, "reason": "", "quality": 0.88, "yaw": 3.2, "pitch": -2.1, "roll": 1.0, "occluded": 0, "face": {"x": 120, "y": 80, "w": 200, "h": 200}}10.4 Upload Face Photo
curl -X POST http://<YOUR_SERVER>/api/upload_face \
-H "Content-Type: application/json" \
-d '{"device_id": "web-demo001", "activation_code": "YOUR_ACTIVATION_CODE", "name": "张三", "image": "data:image/jpeg;base64,..."}'
响应:{"code": 0, "msg": "上传成功", "key": "faces/YOUR_ACTIVATION_CODE/张三_143025.jpg", "url": "http://<YOUR_CDN_DOMAIN>/faces/YOUR_ACTIVATION_CODE/张三_143025.jpg"}