diff --git a/frigate/embeddings/maintainer.py b/frigate/embeddings/maintainer.py index c6add4eb3..338c5a423 100644 --- a/frigate/embeddings/maintainer.py +++ b/frigate/embeddings/maintainer.py @@ -266,6 +266,21 @@ class EmbeddingMaintainer(threading.Thread): "rb", ) as image_file: snapshot_image = image_file.read() + img = cv2.imdecode( + np.frombuffer(snapshot_image, dtype=np.int8), cv2.IMREAD_COLOR + ) + + # crop snapshot based on region before sending off to genai + height, width = img.shape[:2] + x1_rel, y1_rel, width_rel, height_rel = event.data["region"] + + x1, y1 = int(x1_rel * width), int(y1_rel * height) + cropped_image = img[ + y1 : y1 + int(height_rel * height), x1 : x1 + int(width_rel * width) + ] + + _, buffer = cv2.imencode(".jpg", cropped_image) + snapshot_image = buffer.tobytes() embed_image = ( [snapshot_image]