配置修改
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from typing import List, Optional
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from fastapi import APIRouter, Depends, HTTPException, Body
|
||||
from pydantic import BaseModel
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from db.crud import (
|
||||
@@ -16,6 +17,14 @@ from inference.pipeline import get_pipeline
|
||||
router = APIRouter(prefix="/api/cameras", tags=["摄像头管理"])
|
||||
|
||||
|
||||
class CameraUpdateRequest(BaseModel):
|
||||
name: Optional[str] = None
|
||||
rtsp_url: Optional[str] = None
|
||||
fps_limit: Optional[int] = None
|
||||
process_every_n_frames: Optional[int] = None
|
||||
enabled: Optional[bool] = None
|
||||
|
||||
|
||||
@router.get("", response_model=List[dict])
|
||||
def list_cameras(
|
||||
enabled_only: bool = True,
|
||||
@@ -83,29 +92,25 @@ def add_camera(
|
||||
@router.put("/{camera_id}", response_model=dict)
|
||||
def modify_camera(
|
||||
camera_id: int,
|
||||
name: Optional[str] = None,
|
||||
rtsp_url: Optional[str] = None,
|
||||
fps_limit: Optional[int] = None,
|
||||
process_every_n_frames: Optional[int] = None,
|
||||
enabled: Optional[bool] = None,
|
||||
request: CameraUpdateRequest = Body(...),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
camera = update_camera(
|
||||
db,
|
||||
camera_id=camera_id,
|
||||
name=name,
|
||||
rtsp_url=rtsp_url,
|
||||
fps_limit=fps_limit,
|
||||
process_every_n_frames=process_every_n_frames,
|
||||
enabled=enabled,
|
||||
name=request.name,
|
||||
rtsp_url=request.rtsp_url,
|
||||
fps_limit=request.fps_limit,
|
||||
process_every_n_frames=request.process_every_n_frames,
|
||||
enabled=request.enabled,
|
||||
)
|
||||
if not camera:
|
||||
raise HTTPException(status_code=404, detail="摄像头不存在")
|
||||
|
||||
pipeline = get_pipeline()
|
||||
if enabled is True:
|
||||
if request.enabled is True:
|
||||
pipeline.add_camera(camera)
|
||||
elif enabled is False:
|
||||
elif request.enabled is False:
|
||||
pipeline.remove_camera(camera_id)
|
||||
|
||||
return {
|
||||
|
||||
20
config.py
20
config.py
@@ -23,14 +23,16 @@ class DatabaseConfig(BaseModel):
|
||||
|
||||
|
||||
class ModelConfig(BaseModel):
|
||||
engine_path: str = "models/yolo11n_fp16_480.engine"
|
||||
pt_model_path: str = "models/yolo11n.pt"
|
||||
imgsz: List[int] = [480, 480]
|
||||
engine_path: str = "models/yolo11s.engine"
|
||||
onnx_path: str = "models/yolo11s.onnx"
|
||||
pt_model_path: str = "models/yolo11s.pt"
|
||||
imgsz: List[int] = [640, 640]
|
||||
conf_threshold: float = 0.5
|
||||
iou_threshold: float = 0.45
|
||||
device: int = 0
|
||||
batch_size: int = 8
|
||||
half: bool = True
|
||||
use_onnx: bool = True
|
||||
|
||||
|
||||
class StreamConfig(BaseModel):
|
||||
@@ -78,6 +80,17 @@ class LoggingConfig(BaseModel):
|
||||
backup_count: int = 5
|
||||
|
||||
|
||||
class CloudConfig(BaseModel):
|
||||
enabled: bool = False
|
||||
api_url: str = "https://api.example.com"
|
||||
api_key: str = ""
|
||||
device_id: str = "EDGE-001"
|
||||
sync_interval: int = 60
|
||||
alarm_retry_interval: int = 60
|
||||
status_report_interval: int = 60
|
||||
max_retries: int = 3
|
||||
|
||||
|
||||
class MonitoringConfig(BaseModel):
|
||||
enabled: bool = True
|
||||
port: int = 9090
|
||||
@@ -93,6 +106,7 @@ class LLMConfig(BaseModel):
|
||||
|
||||
|
||||
class Config(BaseModel):
|
||||
cloud: CloudConfig = Field(default_factory=CloudConfig)
|
||||
database: DatabaseConfig = Field(default_factory=DatabaseConfig)
|
||||
model: ModelConfig = Field(default_factory=ModelConfig)
|
||||
stream: StreamConfig = Field(default_factory=StreamConfig)
|
||||
|
||||
25
config.yaml
25
config.yaml
@@ -1,5 +1,16 @@
|
||||
# 安保异常行为识别系统 - 核心配置
|
||||
|
||||
# 云端同步配置
|
||||
cloud:
|
||||
enabled: false # 启用云端同步(云端为主、本地为辅)
|
||||
api_url: "https://api.example.com" # 云端API地址
|
||||
api_key: "your-api-key" # API密钥
|
||||
device_id: "EDGE-001" # 设备唯一标识
|
||||
sync_interval: 60 # 配置同步间隔(秒)
|
||||
alarm_retry_interval: 60 # 报警重试间隔(秒)
|
||||
status_report_interval: 60 # 状态上报间隔(秒)
|
||||
max_retries: 3 # 最大重试次数
|
||||
|
||||
# 数据库配置
|
||||
database:
|
||||
dialect: "sqlite" # sqlite 或 mysql
|
||||
@@ -12,21 +23,23 @@ database:
|
||||
|
||||
# TensorRT模型配置
|
||||
model:
|
||||
engine_path: "models/yolo11n_fp16_480.engine"
|
||||
engine_path: "models/yolo11n.engine"
|
||||
onnx_path: "models/yolo11n.onnx"
|
||||
pt_model_path: "models/yolo11n.pt"
|
||||
imgsz: [480, 480]
|
||||
imgsz: [640, 640]
|
||||
conf_threshold: 0.5
|
||||
iou_threshold: 0.45
|
||||
device: 0 # GPU设备号
|
||||
batch_size: 8 # 最大batch size
|
||||
half: true # FP16推理
|
||||
device: 0
|
||||
batch_size: 8
|
||||
half: false
|
||||
use_onnx: true
|
||||
|
||||
# RTSP流配置
|
||||
stream:
|
||||
buffer_size: 2 # 每路摄像头帧缓冲大小
|
||||
reconnect_delay: 3.0 # 重连延迟(秒)
|
||||
timeout: 10.0 # 连接超时(秒)
|
||||
fps_limit: 30 # 最大处理FPS
|
||||
fps_limit: 10.0 # 最大处理FPS
|
||||
|
||||
# 推理队列配置
|
||||
inference:
|
||||
|
||||
@@ -121,8 +121,10 @@ const CameraManagement: React.FC = () => {
|
||||
await axios.put(`/api/cameras/${camera.id}`, { enabled: !camera.enabled });
|
||||
message.success(camera.enabled ? '已停用' : '已启用');
|
||||
fetchCameras();
|
||||
} catch (err) {
|
||||
message.error('操作失败');
|
||||
} catch (err: any) {
|
||||
console.error('Toggle error:', err);
|
||||
const errorMsg = err.response?.data?.detail || err.message || '操作失败';
|
||||
message.error(`操作失败: ${errorMsg}`);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user