违停检测模型改为yolov8s,检测模式修改为手动框选禁停区域
This commit is contained in:
@@ -48,7 +48,8 @@ class DetectionService:
|
||||
model_id: str,
|
||||
confidence: float = 0.5,
|
||||
iou: float = 0.45,
|
||||
algorithm_config: Optional[Dict] = None
|
||||
algorithm_config: Optional[Dict] = None,
|
||||
region_polygon: Optional[List[List[int]]] = None
|
||||
) -> Dict:
|
||||
start_time = time.time()
|
||||
|
||||
@@ -62,6 +63,39 @@ class DetectionService:
|
||||
}
|
||||
|
||||
try:
|
||||
# 违停检测特殊处理:调用专门的违停检测方法
|
||||
if model_id == 'illegal_parking_detection' and hasattr(model, 'detect_illegal_parking'):
|
||||
# 如果提供了禁停区域,单张图片模式下即时判定(时间阈值设为0)
|
||||
parking_time = 0 if region_polygon else None
|
||||
parking_result = model.detect_illegal_parking(
|
||||
image, conf=confidence, illegal_parking_time=parking_time, region_polygon=region_polygon
|
||||
)
|
||||
detections = []
|
||||
for vehicle in parking_result.get('illegal_parking', []):
|
||||
detections.append({
|
||||
'class': 'illegal_parking',
|
||||
'label': '违停车辆',
|
||||
'confidence': 1.0,
|
||||
'bbox': vehicle['bbox'],
|
||||
'track_id': vehicle.get('track_id'),
|
||||
'parking_duration': vehicle.get('parking_duration', 0)
|
||||
})
|
||||
|
||||
processing_time = time.time() - start_time
|
||||
result_data = {
|
||||
'success': parking_result['success'],
|
||||
'message': parking_result.get('message', '违停检测完成'),
|
||||
'detections': detections,
|
||||
'stats': {
|
||||
**parking_result.get('stats', {}),
|
||||
'total_detections': len(detections),
|
||||
'processing_time': round(processing_time, 3),
|
||||
'model_used': model_id
|
||||
}
|
||||
}
|
||||
result_data = self._apply_event_pipeline(result_data, model_id)
|
||||
return result_data
|
||||
|
||||
results = model(image, conf=confidence, iou=iou, verbose=False)
|
||||
|
||||
detections = []
|
||||
@@ -202,6 +236,44 @@ class DetectionService:
|
||||
'stats': None
|
||||
}
|
||||
|
||||
# 违停检测特殊处理:调用专门的违停检测方法
|
||||
if model_id == 'illegal_parking_detection' and hasattr(model, 'detect_illegal_parking'):
|
||||
parking_result = model.detect_illegal_parking(
|
||||
frame, conf=confidence
|
||||
)
|
||||
detections = []
|
||||
for vehicle in parking_result.get('illegal_parking', []):
|
||||
detections.append({
|
||||
'class': 'illegal_parking',
|
||||
'label': '违停车辆',
|
||||
'confidence': 1.0,
|
||||
'bbox': vehicle['bbox'],
|
||||
'track_id': vehicle.get('track_id'),
|
||||
'parking_duration': vehicle.get('parking_duration', 0)
|
||||
})
|
||||
|
||||
processing_time = time.time() - start_time
|
||||
fps = 1.0 / processing_time if processing_time > 0 else 0
|
||||
|
||||
result_data = {
|
||||
'success': parking_result['success'],
|
||||
'message': parking_result.get('message', '违停检测完成'),
|
||||
'detections': detections,
|
||||
'stats': {
|
||||
**parking_result.get('stats', {}),
|
||||
'total_detections': len(detections),
|
||||
'fps': round(fps, 2),
|
||||
'processing_time': round(processing_time, 3),
|
||||
'model_used': model_id
|
||||
}
|
||||
}
|
||||
result_data = self._apply_event_pipeline(result_data, model_id)
|
||||
|
||||
if draw:
|
||||
frame = self.draw_detections(frame, detections, fps)
|
||||
|
||||
return frame, result_data
|
||||
|
||||
results = model(frame, conf=confidence, iou=iou, verbose=False)
|
||||
|
||||
detections = []
|
||||
@@ -579,6 +651,7 @@ class DetectionService:
|
||||
'helmet': (255, 255, 0),
|
||||
'no_helmet': (255, 0, 255),
|
||||
'cigarette': (0, 165, 255),
|
||||
'illegal_parking': (0, 0, 255),
|
||||
# 兼容旧模型类别
|
||||
'violence': (0, 0, 255),
|
||||
'fight': (0, 0, 255),
|
||||
|
||||
Reference in New Issue
Block a user