fix: car detection use wrong image source
All checks were successful
Build Worker Base and Application Images / check-base-changes (push) Successful in 6s
Build Worker Base and Application Images / build-base (push) Has been skipped
Build Worker Base and Application Images / build-docker (push) Successful in 3m34s
Build Worker Base and Application Images / deploy-stack (push) Successful in 15s

This commit is contained in:
ziesorx 2025-10-20 16:54:27 +07:00
parent 5e59e00c55
commit a4cfb264b9
3 changed files with 98 additions and 34 deletions

View file

@ -495,11 +495,13 @@ class DetectionPipeline:
}
valid_detections.append(detection_info)
# Store region for processing phase
detected_regions[class_name] = {
# Store region for processing phase (support multiple detections per class)
if class_name not in detected_regions:
detected_regions[class_name] = []
detected_regions[class_name].append({
'bbox': bbox,
'confidence': confidence
}
})
else:
logger.warning("[DETECTION PHASE] No boxes found in detection results")
@ -951,14 +953,26 @@ class DetectionPipeline:
if region_name and region_name in detected_regions:
# Crop the specified region
bbox = detected_regions[region_name]['bbox']
x1, y1, x2, y2 = [int(coord) for coord in bbox]
cropped = frame[y1:y2, x1:x2]
if cropped.size > 0:
image_to_save = cropped
logger.debug(f"Cropped region '{region_name}' for redis_save_image")
# Handle both list (new) and single dict (backward compat)
regions = detected_regions[region_name]
if isinstance(regions, list):
# Multiple detections - select largest bbox
if regions:
best_region = max(regions, key=lambda r: (r['bbox'][2] - r['bbox'][0]) * (r['bbox'][3] - r['bbox'][1]))
bbox = best_region['bbox']
else:
bbox = None
else:
logger.warning(f"Empty crop for region '{region_name}', using full frame")
bbox = regions['bbox']
if bbox:
x1, y1, x2, y2 = [int(coord) for coord in bbox]
cropped = frame[y1:y2, x1:x2]
if cropped.size > 0:
image_to_save = cropped
logger.debug(f"Cropped region '{region_name}' for redis_save_image")
else:
logger.warning(f"Empty crop for region '{region_name}', using full frame")
# Format key with context
key = action.params['key'].format(**context)