Add wildlife threat classification with size heuristics

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Aaron D. Lee
2026-04-03 13:17:21 -04:00
parent 131eed73b1
commit 13b7c2a219
2 changed files with 88 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
"""Wildlife threat level classification."""
from vigilar.config import WildlifeConfig
from vigilar.detection.person import Detection
def classify_wildlife_threat(
detection: Detection,
config: WildlifeConfig,
frame_area: int,
) -> tuple[str, str]:
"""Classify a wildlife detection into threat level and species.
Returns (threat_level, species_name).
"""
species = detection.class_name
threat_map = config.threat_map
# Direct COCO class mapping first
if species in threat_map.predator:
return "PREDATOR", species
if species in threat_map.nuisance:
return "NUISANCE", species
if species in threat_map.passive:
return "PASSIVE", species
# Fallback to size heuristics for unknown species
_, _, w, h = detection.bbox
bbox_area = w * h
area_ratio = bbox_area / frame_area if frame_area > 0 else 0
heuristics = config.size_heuristics
if area_ratio < heuristics.small:
return "NUISANCE", species
elif area_ratio < heuristics.medium:
return "PREDATOR", species
else:
return "PASSIVE", species