feat(alarm): add alarm snapshot viewing functionality
This commit is contained in:
22
main.py
22
main.py
@@ -11,11 +11,14 @@ os.environ["TENSORRT_DISABLE_MYELIN"] = "1"
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
from fastapi import FastAPI, HTTPException
|
||||
from fastapi import FastAPI, HTTPException, Depends
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.responses import FileResponse, StreamingResponse
|
||||
from sqlalchemy.orm import Session
|
||||
from prometheus_client import start_http_server
|
||||
|
||||
from db.models import get_db
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
from ultralytics.engine.results import Boxes as UltralyticsBoxes
|
||||
@@ -144,6 +147,23 @@ async def get_snapshot_base64(camera_id: int):
|
||||
return {"image": base64.b64encode(buffer).decode("utf-8")}
|
||||
|
||||
|
||||
@app.get("/api/alarms/{alarm_id}/snapshot")
|
||||
async def get_alarm_snapshot(alarm_id: int, db: Session = Depends(get_db)):
|
||||
from db.models import Alarm
|
||||
|
||||
alarm = db.query(Alarm).filter(Alarm.id == alarm_id).first()
|
||||
if not alarm:
|
||||
raise HTTPException(status_code=404, detail="告警不存在")
|
||||
|
||||
if not alarm.snapshot_path:
|
||||
raise HTTPException(status_code=404, detail="该告警没有截图")
|
||||
|
||||
if not os.path.exists(alarm.snapshot_path):
|
||||
raise HTTPException(status_code=404, detail="截图文件不存在")
|
||||
|
||||
return FileResponse(alarm.snapshot_path, media_type="image/jpeg")
|
||||
|
||||
|
||||
@app.get("/api/camera/{camera_id}/detect")
|
||||
async def get_detection_with_overlay(camera_id: int):
|
||||
pipeline = get_pipeline()
|
||||
|
||||
Reference in New Issue
Block a user