feat: implement face filter API for GUI filtering mechanism
- Database schema: face_filter_features and filter_rules tables
- Core engine: FilterEngine with 4 filter rules (landmark, mediapipe, embedding, temporal)
- API endpoints:
- GET /faces - Get faces with filtering
- GET /face/{id}/filter-report - Get filter report for single face
- POST /faces/filter - Apply filter rules
- GET /filter-stats - Get filter statistics
- GET/POST /filter-rules - Manage filter rules
- API documentation for Studio team with examples
- Based on FaceNet analysis results from WD and KOBA videos
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
-- Face Filter Features Table
|
||||
-- Stores computed filter features for each detected face
|
||||
|
||||
CREATE TABLE IF NOT EXISTS face_filter_features (
|
||||
id SERIAL PRIMARY KEY,
|
||||
face_id VARCHAR(255) NOT NULL,
|
||||
file_uuid VARCHAR(32) NOT NULL,
|
||||
frame INTEGER NOT NULL,
|
||||
|
||||
-- Landmark geometric features
|
||||
eye_ratio FLOAT, -- Eye distance / face width (normal: 0.25-0.55)
|
||||
nose_ratio FLOAT, -- Eye-to-nose distance / face height (normal: 0.08-0.25)
|
||||
pose_score FLOAT, -- Sum of absolute roll, yaw, pitch angles
|
||||
|
||||
-- MediaPipe verification features
|
||||
mediapipe_detected BOOLEAN, -- Whether MediaPipe detected this face
|
||||
mediapipe_iou FLOAT, -- IoU between Apple Vision and MediaPipe bbox
|
||||
|
||||
-- Embedding similarity features
|
||||
embedding_similarity FLOAT, -- Max similarity to known faces
|
||||
|
||||
-- Temporal consistency features
|
||||
consecutive_frames INTEGER, -- Number of consecutive frames this face appears
|
||||
total_frames_detected INTEGER, -- Total frames this face was detected
|
||||
|
||||
-- Source information
|
||||
apple_vision_confidence FLOAT,
|
||||
mediapipe_confidence FLOAT,
|
||||
primary_source VARCHAR(50), -- 'apple_vision' or 'mediapipe'
|
||||
|
||||
-- Computed field
|
||||
multi_source_verified BOOLEAN GENERATED ALWAYS AS (
|
||||
mediapipe_detected = TRUE AND mediapipe_iou > 0.3
|
||||
) STORED,
|
||||
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
UNIQUE(file_uuid, face_id)
|
||||
);
|
||||
|
||||
-- Indexes for efficient querying
|
||||
CREATE INDEX IF NOT EXISTS idx_face_filter_file ON face_filter_features(file_uuid);
|
||||
CREATE INDEX IF NOT EXISTS idx_face_filter_face ON face_filter_features(face_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_face_filter_frame ON face_filter_features(file_uuid, frame);
|
||||
|
||||
-- Filter Rules Table
|
||||
-- Stores user-defined filter rules
|
||||
CREATE TABLE IF NOT EXISTS filter_rules (
|
||||
id SERIAL PRIMARY KEY,
|
||||
file_uuid VARCHAR(32) NOT NULL,
|
||||
rule_name VARCHAR(255) NOT NULL,
|
||||
rules JSONB NOT NULL, -- Filter rule configuration
|
||||
is_active BOOLEAN DEFAULT TRUE,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
UNIQUE(file_uuid, rule_name)
|
||||
);
|
||||
|
||||
-- Index for efficient querying
|
||||
CREATE INDEX IF NOT EXISTS idx_filter_rules_file ON filter_rules(file_uuid);
|
||||
|
||||
-- Insert default filter rules
|
||||
INSERT INTO filter_rules (file_uuid, rule_name, rules, is_active)
|
||||
SELECT
|
||||
'default',
|
||||
'default_filter',
|
||||
'{
|
||||
"version": "1.0",
|
||||
"rules": {
|
||||
"landmark_analysis": {
|
||||
"enabled": true,
|
||||
"weight": 0.3,
|
||||
"thresholds": {
|
||||
"eye_ratio_min": 0.25,
|
||||
"eye_ratio_max": 0.55,
|
||||
"nose_ratio_min": 0.08,
|
||||
"pose_score_max": 0.8
|
||||
}
|
||||
},
|
||||
"mediapipe_verification": {
|
||||
"enabled": true,
|
||||
"weight": 0.2,
|
||||
"thresholds": {
|
||||
"min_iou": 0.3
|
||||
}
|
||||
},
|
||||
"embedding_similarity": {
|
||||
"enabled": true,
|
||||
"weight": 0.3,
|
||||
"thresholds": {
|
||||
"min_similarity": 0.70
|
||||
}
|
||||
},
|
||||
"temporal_consistency": {
|
||||
"enabled": true,
|
||||
"weight": 0.2,
|
||||
"thresholds": {
|
||||
"min_consecutive_frames": 3
|
||||
}
|
||||
}
|
||||
},
|
||||
"overall_thresholds": {
|
||||
"auto_accept": 0.7,
|
||||
"auto_reject": 0.3,
|
||||
"review_range": [0.3, 0.7]
|
||||
}
|
||||
}'::jsonb,
|
||||
TRUE
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM filter_rules WHERE file_uuid = 'default' AND rule_name = 'default_filter'
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user