Add wildlife threat classification with size heuristics
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
38
vigilar/detection/wildlife.py
Normal file
38
vigilar/detection/wildlife.py
Normal 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
|
||||
Reference in New Issue
Block a user