mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-04-28 17:47:41 +03:00
Keep track of thumbnial updates
This commit is contained in:
parent
0edbf830e5
commit
9546e0c52f
@ -1,9 +1,13 @@
|
|||||||
"""Post processor for review items to get descriptions."""
|
"""Post processor for review items to get descriptions."""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
|
import cv2
|
||||||
|
|
||||||
|
from frigate.config import FrigateConfig
|
||||||
from frigate.data_processing.types import PostProcessDataEnum
|
from frigate.data_processing.types import PostProcessDataEnum
|
||||||
|
from frigate.genai import GenAIConfig
|
||||||
|
from frigate.genai.ollama import OllamaClient
|
||||||
|
|
||||||
from ..post.api import PostProcessorApi
|
from ..post.api import PostProcessorApi
|
||||||
|
|
||||||
@ -11,15 +15,41 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
class ReviewDescriptionProcessor(PostProcessorApi):
|
class ReviewDescriptionProcessor(PostProcessorApi):
|
||||||
def __init__(self, config, metrics):
|
def __init__(self, config: FrigateConfig, metrics):
|
||||||
super().__init__(config, metrics, None)
|
super().__init__(config, metrics, None)
|
||||||
self.tracked_review_items: dict[str, list[Any]] = {}
|
self.tracked_review_items: dict[str, list[tuple[int, bytes]]] = {}
|
||||||
|
self.genai_client = OllamaClient(
|
||||||
|
GenAIConfig(
|
||||||
|
enabled=True, model="gemma3:4b", base_url="http://192.168.50.107:11434"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def process_data(self, data, data_type):
|
def process_data(self, data, data_type):
|
||||||
if data_type != PostProcessDataEnum.review:
|
if data_type != PostProcessDataEnum.review:
|
||||||
return
|
return
|
||||||
|
|
||||||
logger.info(f"processor is looking at {data}")
|
id = data["after"]["id"]
|
||||||
|
|
||||||
|
if data["type"] == "new" or data["type"] == "update":
|
||||||
|
if id not in self.tracked_review_items:
|
||||||
|
self.tracked_review_items[id] = []
|
||||||
|
|
||||||
|
thumb_time = data["after"]["data"]["thumb_time"]
|
||||||
|
thumb_path = data["after"]["thumb_path"]
|
||||||
|
|
||||||
|
if thumb_time and thumb_path:
|
||||||
|
thumb_data = cv2.imread(thumb_path)
|
||||||
|
ret, jpg = cv2.imencode(
|
||||||
|
".jpg", thumb_data, [int(cv2.IMWRITE_JPEG_QUALITY), 100]
|
||||||
|
)
|
||||||
|
|
||||||
|
if ret:
|
||||||
|
self.tracked_review_items[id].append((thumb_time, jpg.tobytes()))
|
||||||
|
else:
|
||||||
|
logger.info(
|
||||||
|
f"would process review item end with {len(self.tracked_review_items[id])} items"
|
||||||
|
)
|
||||||
|
self.tracked_review_items.pop(id)
|
||||||
|
|
||||||
def handle_request(self, request_data):
|
def handle_request(self, request_data):
|
||||||
pass
|
pass
|
||||||
|
|||||||
@ -152,6 +152,10 @@ class EmbeddingMaintainer(threading.Thread):
|
|||||||
|
|
||||||
self.detected_license_plates: dict[str, dict[str, Any]] = {}
|
self.detected_license_plates: dict[str, dict[str, Any]] = {}
|
||||||
|
|
||||||
|
self.post_processors.append(
|
||||||
|
ReviewDescriptionProcessor(self.config, self.metrics)
|
||||||
|
)
|
||||||
|
|
||||||
# model runners to share between realtime and post processors
|
# model runners to share between realtime and post processors
|
||||||
if self.config.lpr.enabled:
|
if self.config.lpr.enabled:
|
||||||
lpr_model_runner = LicensePlateModelRunner(
|
lpr_model_runner = LicensePlateModelRunner(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user