违停检测模型改为yolov8s,检测模式修改为手动框选禁停区域
This commit is contained in:
@@ -21,11 +21,12 @@ async def detect_image(
|
||||
confidence: float = Query(0.5),
|
||||
iou: float = Query(0.45),
|
||||
algorithm_config: Optional[str] = Query(None, description="算法配置JSON字符串"),
|
||||
composite: bool = Query(False, description="是否启用复合检测(火灾检测时同时检测火焰和烟雾)")
|
||||
composite: bool = Query(False, description="是否启用复合检测(火灾检测时同时检测火焰和烟雾)"),
|
||||
region_polygon: Optional[str] = Query(None, description="禁停区域多边形JSON,例如:[[x1,y1],[x2,y2],...]")
|
||||
):
|
||||
"""
|
||||
图片检测接口
|
||||
|
||||
|
||||
Args:
|
||||
algorithm_config: 算法配置JSON,例如:
|
||||
{
|
||||
@@ -36,6 +37,7 @@ async def detect_image(
|
||||
"loitering_threshold": 300.0,
|
||||
"movement_threshold": 5.0
|
||||
}
|
||||
region_polygon: 禁停区域多边形坐标,用于违停检测
|
||||
"""
|
||||
from main import model_service
|
||||
from services.detection_service import DetectionService
|
||||
@@ -49,19 +51,27 @@ async def detect_image(
|
||||
algo_config = json.loads(algorithm_config)
|
||||
except json.JSONDecodeError as e:
|
||||
logger.warning(f"算法配置解析失败: {e}")
|
||||
|
||||
|
||||
# 解析禁停区域
|
||||
region = None
|
||||
if region_polygon:
|
||||
try:
|
||||
region = json.loads(region_polygon)
|
||||
except json.JSONDecodeError as e:
|
||||
logger.warning(f"禁停区域解析失败: {e}")
|
||||
|
||||
try:
|
||||
contents = await file.read()
|
||||
nparr = np.frombuffer(contents, np.uint8)
|
||||
frame = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
|
||||
|
||||
|
||||
if frame is None:
|
||||
return ImageDetectionResult(
|
||||
success=False,
|
||||
message="无法读取图片",
|
||||
data={}
|
||||
)
|
||||
|
||||
|
||||
# 判断是否启用复合火灾检测
|
||||
if composite and model_id == 'fire_detection':
|
||||
result = await detection_service.detect_fire_composite(
|
||||
@@ -69,7 +79,9 @@ async def detect_image(
|
||||
)
|
||||
else:
|
||||
result = await detection_service.detect_image(
|
||||
frame, model_id, confidence, iou, algorithm_config=algo_config
|
||||
frame, model_id, confidence, iou,
|
||||
algorithm_config=algo_config,
|
||||
region_polygon=region
|
||||
)
|
||||
|
||||
if result['success']:
|
||||
|
||||
Reference in New Issue
Block a user