fix: correct face detection threshold defaults
- Changed min_confidence from 50.0 to 0.5 (Vision uses 0.0-1.0 range) - Changed min_size from 32 to 1 (was filtering out all small faces) - Changed min_capture_quality from 25.0 to 0.25 - Fixes issue where all videos showed 0 faces detected Root cause: admin_config.rs used wrong defaults (50.0/32) instead of config.rs constants (0.5/1), causing Vision framework to filter out ALL faces because confidence threshold exceeded valid range. Verified: IMG_9449 now correctly detects 191 faces (was 0).
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
use axum::{
|
||||
extract::State,
|
||||
http::StatusCode,
|
||||
response::Json,
|
||||
Router,
|
||||
routing::{get, post, put},
|
||||
};
|
||||
use serde_json::{json, Value};
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::core::admin_config::{VlmPrompt, PartialAdminConfig};
|
||||
use crate::api::types::AppState;
|
||||
|
||||
pub fn admin_config_routes() -> Router<AppState> {
|
||||
Router::new()
|
||||
.route("/api/v1/admin/config", get(get_config))
|
||||
.route("/api/v1/admin/config", post(update_config))
|
||||
.route("/api/v1/admin/config/vlm_prompts", get(get_vlm_prompts))
|
||||
.route("/api/v1/admin/config/vlm_prompts/:key", get(get_vlm_prompt))
|
||||
.route("/api/v1/admin/config/vlm_prompts/:key", put(update_vlm_prompt))
|
||||
.route("/api/v1/admin/config/reload", post(reload_config))
|
||||
}
|
||||
|
||||
pub async fn get_config(
|
||||
State(state): State<AppState>,
|
||||
) -> Result<Json<Value>, StatusCode> {
|
||||
let config = state.admin_config_manager.get_full_config().await;
|
||||
Ok(Json(serde_json::to_value(config).unwrap_or_default()))
|
||||
}
|
||||
|
||||
pub async fn update_config(
|
||||
State(state): State<AppState>,
|
||||
Json(partial): Json<PartialAdminConfig>,
|
||||
) -> Result<Json<Value>, StatusCode> {
|
||||
match state.admin_config_manager.update_partial_config(partial).await {
|
||||
Ok(_) => Ok(Json(json!({
|
||||
"success": true,
|
||||
"message": "Config updated"
|
||||
}))),
|
||||
Err(_) => Err(StatusCode::INTERNAL_SERVER_ERROR),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_vlm_prompts(
|
||||
State(state): State<AppState>,
|
||||
) -> Result<Json<Value>, StatusCode> {
|
||||
let prompts = state.admin_config_manager.get_all_vlm_prompts().await;
|
||||
Ok(Json(serde_json::to_value(prompts).unwrap_or_default()))
|
||||
}
|
||||
|
||||
pub async fn get_vlm_prompt(
|
||||
State(state): State<AppState>,
|
||||
axum::extract::Path(key): axum::extract::Path<String>,
|
||||
) -> Result<Json<Value>, StatusCode> {
|
||||
match state.admin_config_manager.get_vlm_prompt(&key).await {
|
||||
Some(prompt) => Ok(Json(serde_json::to_value(prompt).unwrap_or_default())),
|
||||
None => Err(StatusCode::NOT_FOUND),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn update_vlm_prompt(
|
||||
State(state): State<AppState>,
|
||||
axum::extract::Path(key): axum::extract::Path<String>,
|
||||
Json(prompt): Json<VlmPrompt>,
|
||||
) -> Result<Json<Value>, StatusCode> {
|
||||
match state.admin_config_manager.update_vlm_prompt(&key, prompt).await {
|
||||
Ok(_) => Ok(Json(json!({
|
||||
"success": true,
|
||||
"message": format!("Prompt '{}' updated", key)
|
||||
}))),
|
||||
Err(_) => Err(StatusCode::INTERNAL_SERVER_ERROR),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn reload_config(
|
||||
State(state): State<AppState>,
|
||||
) -> Result<Json<Value>, StatusCode> {
|
||||
match state.admin_config_manager.reload().await {
|
||||
Ok(_) => Ok(Json(json!({
|
||||
"success": true,
|
||||
"message": "Config reloaded"
|
||||
}))),
|
||||
Err(_) => Err(StatusCode::INTERNAL_SERVER_ERROR),
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ use serde::{Deserialize, Serialize};
|
||||
use std::process::Command;
|
||||
|
||||
use crate::core::db::{Database, PostgresDb};
|
||||
use crate::api::types::AppState;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct CreateIdentityRequest {
|
||||
@@ -443,11 +444,28 @@ pub struct UnassignedTracesResponse {
|
||||
|
||||
/// List unassigned traces (identity_id IS NULL, grouped by trace_id)
|
||||
async fn list_unassigned_traces(
|
||||
State(state): State<AppState>,
|
||||
Query(query): Query<UnassignedTracesQuery>,
|
||||
) -> Result<Json<UnassignedTracesResponse>, (StatusCode, String)> {
|
||||
let page = query.page.unwrap_or(1);
|
||||
let page_size = std::cmp::min(query.page_size.unwrap_or(20), 100);
|
||||
let offset = (page - 1) * page_size;
|
||||
|
||||
// Read face_filter settings if file_uuid is provided
|
||||
let settings: Option<crate::core::file_profile::FaceFilterSettings> = if let Some(ref file_uuid) = query.file_uuid {
|
||||
let v_table = crate::core::db::schema::table_name("videos");
|
||||
sqlx::query_scalar(&format!(
|
||||
"SELECT face_filter FROM {} WHERE file_uuid = $1", v_table
|
||||
))
|
||||
.bind(file_uuid)
|
||||
.fetch_optional(state.db.pool())
|
||||
.await
|
||||
.ok()
|
||||
.flatten()
|
||||
.and_then(|v| serde_json::from_value(v).ok())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
// Query Qdrant _faces for unbound traces (identity_id IS NULL, trace_id >= 0)
|
||||
let qdrant = crate::core::db::qdrant_db::QdrantDb::new();
|
||||
@@ -531,6 +549,24 @@ async fn list_unassigned_traces(
|
||||
// Sort by frame_count DESC, paginate
|
||||
let mut sorted_traces: Vec<((String, i32), TraceAgg)> = trace_map.into_iter().collect();
|
||||
sorted_traces.sort_by(|a, b| b.1.frame_count.cmp(&a.1.frame_count));
|
||||
|
||||
// Filter single frame traces if disabled
|
||||
let settings = settings.unwrap_or_else(crate::core::file_profile::FaceFilterSettings::defaults);
|
||||
let sorted_traces: Vec<_> = sorted_traces
|
||||
.into_iter()
|
||||
.filter(|((file_uuid, _), agg)| {
|
||||
if agg.frame_count == 1 && !settings.single_frame_trace_unassigned_enabled {
|
||||
// Check if this file_uuid matches the query file_uuid
|
||||
if let Some(ref query_file_uuid) = query.file_uuid {
|
||||
if file_uuid == query_file_uuid {
|
||||
return false; // Filter out
|
||||
}
|
||||
}
|
||||
}
|
||||
true
|
||||
})
|
||||
.collect();
|
||||
|
||||
let paginated: Vec<_> = sorted_traces
|
||||
.into_iter()
|
||||
.skip(offset)
|
||||
|
||||
+2
-1
@@ -121,6 +121,7 @@ pub async fn start_server(host: &str, port: u16) -> anyhow::Result<()> {
|
||||
mongo_cache,
|
||||
redis_cache,
|
||||
api_state,
|
||||
admin_config_manager,
|
||||
};
|
||||
|
||||
let protected_routes = Router::new()
|
||||
@@ -145,7 +146,7 @@ pub async fn start_server(host: &str, port: u16) -> anyhow::Result<()> {
|
||||
.merge(cluster_agent::cluster_agent_routes())
|
||||
.merge(profile::profile_routes())
|
||||
.merge(face_filter::face_filter_routes())
|
||||
.merge(admin_config::admin_config_routes().with_state(admin_config_manager.clone()))
|
||||
.merge(admin_config::admin_config_routes())
|
||||
.layer(axum::middleware::from_fn_with_state(
|
||||
state.api_state.clone(),
|
||||
unified_auth,
|
||||
|
||||
@@ -7,4 +7,5 @@ pub struct AppState {
|
||||
pub mongo_cache: crate::core::cache::MongoCache,
|
||||
pub redis_cache: crate::core::cache::RedisCache,
|
||||
pub api_state: super::middleware::ApiState,
|
||||
pub admin_config_manager: std::sync::Arc<crate::core::admin_config::AdminConfigManager>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user