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:
Accusys
2026-09-18 02:42:21 +08:00
parent e4b8ddab94
commit 31d1b4050f
59 changed files with 11110 additions and 6163 deletions
+146 -144
View File
@@ -2,10 +2,13 @@ use once_cell::sync::Lazy;
use std::env;
use std::sync::RwLock;
// ─────────────────────────────────────────────────────────────
// Runtime switches (mutable via API, persisted in memory)
// ─────────────────────────────────────────────────────────────
pub static RUNTIME_CACHE_ENABLED: Lazy<RwLock<bool>> = Lazy::new(|| {
let initial = env::var("MONGODB_CACHE_ENABLED")
.unwrap_or_else(|_| "true".to_string())
.parse()
.map(|v| v == "true" || v == "1")
.unwrap_or(true);
RwLock::new(initial)
});
@@ -19,7 +22,6 @@ pub fn set_cache_enabled(enabled: bool) {
tracing::info!("Cache enabled set to: {}", enabled);
}
// Switch 1: watcher detects new file → auto-register
pub static RUNTIME_WATCHER_AUTO_REGISTER: Lazy<RwLock<bool>> = Lazy::new(|| RwLock::new(false));
pub fn get_watcher_auto_register() -> bool {
@@ -31,7 +33,6 @@ pub fn set_watcher_auto_register(enabled: bool) {
tracing::info!("Watcher auto-register set to: {}", enabled);
}
// Switch 2: register → auto-trigger processing pipeline
pub static RUNTIME_AUTO_PIPELINE_ENABLED: Lazy<RwLock<bool>> = Lazy::new(|| RwLock::new(false));
pub fn get_auto_pipeline_enabled() -> bool {
@@ -65,7 +66,6 @@ pub static MONGODB_URL: Lazy<String> = Lazy::new(|| {
pub static REDIS_URL: Lazy<String> = Lazy::new(|| {
env::var("REDIS_URL").unwrap_or_else(|_| {
let password = env::var("REDIS_PASSWORD").unwrap_or_else(|_| "accusys".to_string());
// Format: redis://[:password]@host:port (use default user)
format!("redis://default:{}@localhost:6379", password)
})
});
@@ -73,28 +73,81 @@ pub static REDIS_URL: Lazy<String> = Lazy::new(|| {
pub static REDIS_PASSWORD: Lazy<String> =
Lazy::new(|| env::var("REDIS_PASSWORD").unwrap_or_else(|_| "accusys".to_string()));
pub static JWT_SECRET: Lazy<String> = Lazy::new(|| {
env::var("JWT_SECRET").unwrap_or_else(|_| "momentry_default_jwt_secret_change_me".to_string())
});
pub static DATABASE_SCHEMA: Lazy<String> =
Lazy::new(|| env::var("DATABASE_SCHEMA").unwrap_or_else(|_| "public".to_string()));
pub static SYSTEM_TIMEZONE: Lazy<String> = Lazy::new(|| {
if let Ok(tz) = env::var("MOMENTRY_TIMEZONE") {
if !tz.is_empty() {
return tz;
}
}
if let Ok(tz) = env::var("TZ") {
if !tz.is_empty() {
return tz;
}
}
if let Ok(path) = std::fs::read_link("/etc/localtime") {
let s = path.to_string_lossy();
for prefix in &["/usr/share/zoneinfo/", "/var/db/timezone/zoneinfo/"] {
if let Some(tz) = s.strip_prefix(prefix) {
return tz.to_string();
}
}
}
"Asia/Taipei".to_string()
});
pub static MONGODB_DATABASE: Lazy<String> =
Lazy::new(|| env::var("MONGODB_DATABASE").unwrap_or_else(|_| "momentry".to_string()));
pub static QDRANT_COLLECTION: Lazy<String> =
Lazy::new(|| env::var("QDRANT_COLLECTION").unwrap_or_else(|_| "momentry_rule1".to_string()));
pub static REDIS_KEY_PREFIX: Lazy<String> =
Lazy::new(|| env::var("MOMENTRY_REDIS_PREFIX").unwrap_or_else(|_| "momentry:".to_string()));
pub static SFTPGO_BASE_URL: Lazy<String> = Lazy::new(|| {
env::var("SFTPGO_BASE_URL").unwrap_or_else(|_| "http://127.0.0.1:8080".to_string())
});
pub static OLLAMA_URL: Lazy<String> = Lazy::new(|| {
env::var("MOMENTRY_OLLAMA_URL").unwrap_or_else(|_| "http://127.0.0.1:11434".to_string())
});
pub static EMBED_URL: Lazy<String> = Lazy::new(|| {
env::var("MOMENTRY_EMBED_URL").unwrap_or_else(|_| "http://127.0.0.1:11436".to_string())
});
pub static LLM_HEALTH_URL: Lazy<String> = Lazy::new(|| {
env::var("MOMENTRY_LLM_HEALTH_URL").unwrap_or_else(|_| {
"http://127.0.0.1:8080/health".to_string()
})
});
// ─────────────────────────────────────────────────────────────
// JSON-backed configs (paths, concurrency, feature flags)
// These read from admin_config.json with ENV fallback
// ─────────────────────────────────────────────────────────────
pub static OUTPUT_DIR: Lazy<String> = Lazy::new(|| {
env::var("MOMENTRY_OUTPUT_DIR").unwrap_or_else(|_| "/Users/accusys/momentry/output".to_string())
crate::core::admin_config::get_output_dir()
});
pub static BACKUP_DIR: Lazy<String> = Lazy::new(|| {
env::var("MOMENTRY_BACKUP_DIR")
.unwrap_or_else(|_| "/Users/accusys/momentry/backup/momentry".to_string())
});
pub static PYTHON_PATH: Lazy<String> = Lazy::new(|| {
env::var("MOMENTRY_PYTHON_PATH").unwrap_or_else(|_| "/opt/homebrew/bin/python3.11".to_string())
crate::core::admin_config::get_backup_dir()
});
pub static SCRIPTS_DIR: Lazy<String> = Lazy::new(|| {
env::var("MOMENTRY_SCRIPTS_DIR")
.unwrap_or_else(|_| "/Users/accusys/momentry_core_0.1/scripts".to_string())
crate::core::admin_config::get_scripts_dir()
});
pub static LOG_LEVEL: Lazy<String> = Lazy::new(|| {
env::var("RUST_LOG")
.or_else(|_| env::var("MOMENTRY_LOG_LEVEL"))
.unwrap_or_else(|_| "info".to_string())
pub static PYTHON_PATH: Lazy<String> = Lazy::new(|| {
crate::core::admin_config::get_python_path()
});
pub static MEDIA_BASE_URL: Lazy<String> = Lazy::new(|| {
@@ -114,143 +167,98 @@ pub static SERVE_BASE_URL: Lazy<String> = Lazy::new(|| {
pub static SERVER_PORT: Lazy<u16> = Lazy::new(|| {
env::var("MOMENTRY_SERVER_PORT")
.unwrap_or_else(|_| "3002".to_string())
.parse()
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(3002)
});
pub static REDIS_KEY_PREFIX: Lazy<String> =
Lazy::new(|| env::var("MOMENTRY_REDIS_PREFIX").unwrap_or_else(|_| "momentry:".to_string()));
// ─────────────────────────────────────────────────────────────
// Face detection thresholds (single source of truth)
// ─────────────────────────────────────────────────────────────
pub static DATABASE_SCHEMA: Lazy<String> =
Lazy::new(|| env::var("DATABASE_SCHEMA").unwrap_or_else(|_| "public".to_string()));
pub const FACE_MIN_CONFIDENCE_DEFAULT: f64 = 0.5;
pub const FACE_MIN_SIZE_DEFAULT: i32 = 1;
pub const FACE_FILTER_CONFIDENCE_PCT_DEFAULT: f64 = 50.0;
pub static SYSTEM_TIMEZONE: Lazy<String> = Lazy::new(|| {
if let Ok(tz) = env::var("MOMENTRY_TIMEZONE") {
if !tz.is_empty() {
return tz;
}
}
if let Ok(tz) = env::var("TZ") {
if !tz.is_empty() {
return tz;
}
}
// macOS: /etc/localtime → /var/db/timezone/zoneinfo/Asia/Taipei
// Linux: /etc/localtime → /usr/share/zoneinfo/Asia/Taipei
if let Ok(path) = std::fs::read_link("/etc/localtime") {
let s = path.to_string_lossy();
for prefix in &["/usr/share/zoneinfo/", "/var/db/timezone/zoneinfo/"] {
if let Some(tz) = s.strip_prefix(prefix) {
return tz.to_string();
}
}
}
"Asia/Taipei".to_string()
});
pub static MONGODB_DATABASE: Lazy<String> =
Lazy::new(|| env::var("MONGODB_DATABASE").unwrap_or_else(|_| "momentry".to_string()));
pub static QDRANT_COLLECTION: Lazy<String> =
Lazy::new(|| env::var("QDRANT_COLLECTION").unwrap_or_else(|_| "momentry_rule1".to_string()));
// ─── Face detection thresholds (single source of truth) ───
// Defaults mirror Apple Vision native detection (0.5 confidence / 1px min size).
// Keep scripts/swift_processors/swift_face.swift and scripts/face_processor.py in sync.
pub const FACE_MIN_CONFIDENCE_DEFAULT: f64 = 0.5; // detection threshold (0-1)
pub const FACE_MIN_SIZE_DEFAULT: i32 = 1; // detection min face size (px)
pub const FACE_FILTER_CONFIDENCE_PCT_DEFAULT: f64 = 50.0; // videos.face_filter (0-100%)
pub mod processor {
use super::*;
pub static ASR_TIMEOUT_SECS: Lazy<u64> = Lazy::new(|| {
env::var("MOMENTRY_ASR_TIMEOUT")
.unwrap_or_else(|_| "3600".to_string())
.parse()
.unwrap_or(3600)
});
pub static CUT_TIMEOUT_SECS: Lazy<u64> = Lazy::new(|| {
env::var("MOMENTRY_CUT_TIMEOUT")
.unwrap_or_else(|_| "3600".to_string())
.parse()
.unwrap_or(3600)
});
pub static DEFAULT_TIMEOUT_SECS: Lazy<u64> = Lazy::new(|| {
env::var("MOMENTRY_DEFAULT_TIMEOUT")
.unwrap_or_else(|_| "7200".to_string())
.parse()
.unwrap_or(7200)
});
pub static FORCE_RETRY: Lazy<bool> = Lazy::new(|| {
env::var("MOMENTRY_FORCE_RETRY")
.map(|v| v == "true" || v == "1")
.unwrap_or(false)
});
}
// ─────────────────────────────────────────────────────────────
// Cache TTLs
// ─────────────────────────────────────────────────────────────
pub mod cache {
use super::*;
pub static MONGODB_CACHE_ENABLED: Lazy<bool> = Lazy::new(|| {
env::var("MONGODB_CACHE_ENABLED")
.unwrap_or_else(|_| "true".to_string())
.parse()
.map(|v| v == "true" || v == "1")
.unwrap_or(true)
});
pub static MONGODB_CACHE_TTL_VIDEOS: Lazy<u64> = Lazy::new(|| {
env::var("MONGODB_CACHE_TTL_VIDEOS")
.unwrap_or_else(|_| "300".to_string())
.parse()
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(300)
});
pub static MONGODB_CACHE_TTL_SEARCH: Lazy<u64> = Lazy::new(|| {
env::var("MONGODB_CACHE_TTL_SEARCH")
.unwrap_or_else(|_| "300".to_string())
.parse()
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(300)
});
pub static MONGODB_CACHE_TTL_HYBRID_SEARCH: Lazy<u64> = Lazy::new(|| {
env::var("MONGODB_CACHE_TTL_HYBRID_SEARCH")
.unwrap_or_else(|_| "600".to_string())
.parse()
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(600)
});
pub static MONGODB_CACHE_TTL_VIDEO_META: Lazy<u64> = Lazy::new(|| {
env::var("MONGODB_CACHE_TTL_VIDEO_META")
.unwrap_or_else(|_| "3600".to_string())
.parse()
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(3600)
});
pub static REDIS_CACHE_TTL_HEALTH: Lazy<u64> = Lazy::new(|| {
env::var("REDIS_CACHE_TTL_HEALTH")
.unwrap_or_else(|_| "30".to_string())
.parse()
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(30)
});
pub static REDIS_CACHE_TTL_VIDEO_META: Lazy<u64> = Lazy::new(|| {
env::var("REDIS_CACHE_TTL_VIDEO_META")
.unwrap_or_else(|_| "3600".to_string())
.parse()
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(3600)
});
}
// ─────────────────────────────────────────────────────────────
// TMDB
// ─────────────────────────────────────────────────────────────
pub mod tmdb {
use super::*;
pub static API_KEY: Lazy<Option<String>> = Lazy::new(|| env::var("TMDB_API_KEY").ok());
pub static PROBE_ENABLED: Lazy<bool> = Lazy::new(|| {
env::var("MOMENTRY_TMDB_PROBE_ENABLED")
.map(|v| v == "true" || v == "1")
.unwrap_or(false)
});
}
// ─────────────────────────────────────────────────────────────
// LLM endpoints (chat, vision, summary, embedding)
// ─────────────────────────────────────────────────────────────
pub mod llm {
use super::*;
/// Chat / function-calling LLM endpoint (agents/search, translation, etc.)
/// Default: MarkBaseEngine on http://127.0.0.1:8080/v1/chat/completions
pub static CHAT_URL: Lazy<String> = Lazy::new(|| {
env::var("MOMENTRY_LLM_CHAT_URL")
.or_else(|_| env::var("MOMENTRY_LLM_SUMMARY_URL"))
@@ -265,15 +273,12 @@ pub mod llm {
.unwrap_or_else(|_| "e4b".to_string())
});
/// Vision LLM endpoint (frame analysis, OCR). Can be same as CHAT_URL or different.
/// Default: falls back to CHAT_URL
pub static VISION_URL: Lazy<String> =
Lazy::new(|| env::var("MOMENTRY_LLM_VISION_URL").unwrap_or_else(|_| CHAT_URL.clone()));
pub static VISION_MODEL: Lazy<String> =
Lazy::new(|| env::var("MOMENTRY_LLM_VISION_MODEL").unwrap_or_else(|_| CHAT_MODEL.clone()));
/// Text summary LLM endpoint (5W1H, story). Can be same as CHAT_URL or different.
pub static SUMMARY_URL: Lazy<String> = Lazy::new(|| {
env::var("MOMENTRY_LLM_SUMMARY_URL")
.ok()
@@ -290,8 +295,8 @@ pub mod llm {
pub static SUMMARY_TIMEOUT_SECS: Lazy<u64> = Lazy::new(|| {
env::var("MOMENTRY_LLM_SUMMARY_TIMEOUT")
.unwrap_or_else(|_| "120".to_string())
.parse()
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(120)
});
@@ -303,46 +308,43 @@ pub mod llm {
pub static CHAT_TIMEOUT_SECS: Lazy<u64> = Lazy::new(|| {
env::var("MOMENTRY_LLM_CHAT_TIMEOUT")
.unwrap_or_else(|_| "120".to_string())
.parse()
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(120)
});
}
/// Ollama embedding endpoint (vector embeddings for text sync).
pub static OLLAMA_URL: Lazy<String> = Lazy::new(|| {
env::var("MOMENTRY_OLLAMA_URL").unwrap_or_else(|_| "http://127.0.0.1:11434".to_string())
});
// ─────────────────────────────────────────────────────────────
// Processor timeouts
// ─────────────────────────────────────────────────────────────
/// Text embedding server (comic-embed or alternative).
pub static EMBED_URL: Lazy<String> = Lazy::new(|| {
env::var("MOMENTRY_EMBED_URL").unwrap_or_else(|_| "http://127.0.0.1:11436".to_string())
});
/// LLM health endpoint.
pub static LLM_HEALTH_URL: Lazy<String> = Lazy::new(|| {
env::var("MOMENTRY_LLM_HEALTH_URL").unwrap_or_else(|_| {
let chat = llm::CHAT_URL.clone();
chat.trim_end_matches("/v1/chat/completions").to_string() + "/health"
})
});
pub static SFTPGO_BASE_URL: Lazy<String> = Lazy::new(|| {
env::var("SFTPGO_BASE_URL").unwrap_or_else(|_| "http://127.0.0.1:8080".to_string())
});
pub static JWT_SECRET: Lazy<String> = Lazy::new(|| {
env::var("JWT_SECRET").unwrap_or_else(|_| "momentry_default_jwt_secret_change_me".to_string())
});
pub mod tmdb {
pub mod processor {
use super::*;
pub static API_KEY: Lazy<Option<String>> = Lazy::new(|| env::var("TMDB_API_KEY").ok());
pub static ASR_TIMEOUT_SECS: Lazy<u64> = Lazy::new(|| {
env::var("MOMENTRY_ASR_TIMEOUT")
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(3600)
});
pub static PROBE_ENABLED: Lazy<bool> = Lazy::new(|| {
env::var("MOMENTRY_TMDB_PROBE_ENABLED")
pub static CUT_TIMEOUT_SECS: Lazy<u64> = Lazy::new(|| {
env::var("MOMENTRY_CUT_TIMEOUT")
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(3600)
});
pub static DEFAULT_TIMEOUT_SECS: Lazy<u64> = Lazy::new(|| {
env::var("MOMENTRY_DEFAULT_TIMEOUT")
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(7200)
});
pub static FORCE_RETRY: Lazy<bool> = Lazy::new(|| {
env::var("MOMENTRY_FORCE_RETRY")
.map(|v| v == "true" || v == "1")
.unwrap_or(false)
});
}
}