mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-11 05:35:25 +03:00
Send camera activitiy in on connect
This commit is contained in:
parent
96061df5f5
commit
839f35f0a1
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
|
import json
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from typing import Any, Callable, Optional
|
from typing import Any, Callable, Optional
|
||||||
|
|
||||||
@ -127,6 +128,8 @@ class Dispatcher:
|
|||||||
).execute()
|
).execute()
|
||||||
elif topic == UPDATE_CAMERA_ACTIVITY:
|
elif topic == UPDATE_CAMERA_ACTIVITY:
|
||||||
self.camera_activity = payload
|
self.camera_activity = payload
|
||||||
|
elif topic == "onConnect":
|
||||||
|
self.publish("camera_activity", json.dumps(self.camera_activity))
|
||||||
else:
|
else:
|
||||||
self.publish(topic, payload, retain=False)
|
self.publish(topic, payload, retain=False)
|
||||||
|
|
||||||
|
|||||||
@ -50,6 +50,10 @@ class WebSocketClient(Communicator): # type: ignore[misc]
|
|||||||
class _WebSocketHandler(WebSocket): # type: ignore[misc]
|
class _WebSocketHandler(WebSocket): # type: ignore[misc]
|
||||||
receiver = self._dispatcher
|
receiver = self._dispatcher
|
||||||
|
|
||||||
|
def opened(self) -> None:
|
||||||
|
"""A new websocket is opened, we need to send an update message"""
|
||||||
|
self.receiver("onConnect", "")
|
||||||
|
|
||||||
def received_message(self, message: WebSocket.received_message) -> None:
|
def received_message(self, message: WebSocket.received_message) -> None:
|
||||||
try:
|
try:
|
||||||
json_message = json.loads(message.data.decode("utf-8"))
|
json_message = json.loads(message.data.decode("utf-8"))
|
||||||
|
|||||||
@ -25,7 +25,7 @@ from frigate.config import (
|
|||||||
SnapshotsConfig,
|
SnapshotsConfig,
|
||||||
ZoomingModeEnum,
|
ZoomingModeEnum,
|
||||||
)
|
)
|
||||||
from frigate.const import CLIPS_DIR, UPDATE_CAMERA_ACTIVITY
|
from frigate.const import ALL_ATTRIBUTE_LABELS, CLIPS_DIR, UPDATE_CAMERA_ACTIVITY
|
||||||
from frigate.events.types import EventStateEnum, EventTypeEnum
|
from frigate.events.types import EventStateEnum, EventTypeEnum
|
||||||
from frigate.ptz.autotrack import PtzAutoTrackerThread
|
from frigate.ptz.autotrack import PtzAutoTrackerThread
|
||||||
from frigate.util.image import (
|
from frigate.util.image import (
|
||||||
@ -538,7 +538,9 @@ class CameraState:
|
|||||||
):
|
):
|
||||||
max_target_box = self.ptz_autotracker_thread.ptz_autotracker.tracked_object_metrics[
|
max_target_box = self.ptz_autotracker_thread.ptz_autotracker.tracked_object_metrics[
|
||||||
self.name
|
self.name
|
||||||
]["max_target_box"]
|
][
|
||||||
|
"max_target_box"
|
||||||
|
]
|
||||||
side_length = max_target_box * (
|
side_length = max_target_box * (
|
||||||
max(
|
max(
|
||||||
self.camera_config.detect.width,
|
self.camera_config.detect.width,
|
||||||
@ -736,19 +738,22 @@ class CameraState:
|
|||||||
< self.camera_config.detect.stationary.threshold
|
< self.camera_config.detect.stationary.threshold
|
||||||
)
|
)
|
||||||
|
|
||||||
if (
|
if not obj.false_positive:
|
||||||
obj.obj_data["position_changes"] > 0
|
label = object_type
|
||||||
and not obj.obj_data["false_positive"]
|
|
||||||
):
|
if (
|
||||||
if object_type not in camera_activity:
|
obj.obj_data.get("sub_label")
|
||||||
camera_activity[object_type] = {
|
and obj.obj_data.get("sub_label")[0] in ALL_ATTRIBUTE_LABELS
|
||||||
|
):
|
||||||
|
label = obj.obj_data["sub_label"]
|
||||||
|
|
||||||
|
if label not in camera_activity:
|
||||||
|
camera_activity[label] = {
|
||||||
"active": 1 if active else 0,
|
"active": 1 if active else 0,
|
||||||
"stationary": 1 if not active else 0,
|
"stationary": 1 if not active else 0,
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
camera_activity[object_type][
|
camera_activity[label]["active" if active else "stationary"] += 1
|
||||||
"active" if active else "stationary"
|
|
||||||
] += 1
|
|
||||||
|
|
||||||
# if the object's thumbnail is not from the current frame
|
# if the object's thumbnail is not from the current frame
|
||||||
if obj.false_positive or obj.thumbnail_data["frame_time"] != frame_time:
|
if obj.false_positive or obj.thumbnail_data["frame_time"] != frame_time:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user