Keep track of thumbnial updates

This commit is contained in:
Nicolas Mowen 2025-08-03 10:06:38 -06:00
parent 0edbf830e5
commit 9546e0c52f
2 changed files with 38 additions and 4 deletions

View File

@ -1,9 +1,13 @@
"""Post processor for review items to get descriptions."""
import logging
from typing import Any
import cv2
from frigate.config import FrigateConfig
from frigate.data_processing.types import PostProcessDataEnum
from frigate.genai import GenAIConfig
from frigate.genai.ollama import OllamaClient
from ..post.api import PostProcessorApi
@ -11,15 +15,41 @@ logger = logging.getLogger(__name__)
class ReviewDescriptionProcessor(PostProcessorApi):
def __init__(self, config, metrics):
def __init__(self, config: FrigateConfig, metrics):
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):
if data_type != PostProcessDataEnum.review:
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):
pass

View File

@ -152,6 +152,10 @@ class EmbeddingMaintainer(threading.Thread):
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
if self.config.lpr.enabled:
lpr_model_runner = LicensePlateModelRunner(