update tracker

This commit is contained in:
Pongsatorn 2025-08-20 21:26:54 +07:00
parent a54da904f7
commit 3a4a27ca68
7 changed files with 1405 additions and 84 deletions

7
app.py
View file

@ -27,7 +27,7 @@ from websockets.exceptions import ConnectionClosedError
from ultralytics import YOLO
# Import shared pipeline functions
from siwatsystem.pympta import load_pipeline_from_zip, run_pipeline
from siwatsystem.pympta import load_pipeline_from_zip, run_pipeline, cleanup_camera_stability
app = FastAPI()
@ -325,6 +325,7 @@ async def detect(websocket: WebSocket):
"type": "imageDetection",
"subscriptionIdentifier": stream["subscriptionIdentifier"],
"timestamp": time.strftime("%Y-%m-%dT%H:%M:%S.%fZ", time.gmtime()),
# "timestamp": time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime()) + f".{int(time.time() * 1000) % 1000:03d}Z",
"data": {
"detection": detection_dict,
"modelId": stream["modelId"],
@ -704,6 +705,7 @@ async def detect(websocket: WebSocket):
del camera_streams[camera_url]
latest_frames.pop(subscription_id, None)
cleanup_camera_stability(subscription_id)
logger.info(f"Unsubscribed from camera {subscription_id}")
async def process_streams():
@ -1018,8 +1020,9 @@ async def detect(websocket: WebSocket):
else:
logger.info(f"Shared stream for {camera_url} still has {shared_stream['ref_count']} references")
# Clean up cached frame
# Clean up cached frame and stability tracking
latest_frames.pop(camera_id, None)
cleanup_camera_stability(camera_id)
logger.info(f"Unsubscribed from camera {camera_id}")
# Note: Keep models in memory for potential reuse
elif msg_type == "requestState":