crop snapshot to region

This commit is contained in:
Josh Hawkins 2024-09-30 16:20:21 -05:00
parent 9fd94c6390
commit e9e2996428

View File

@ -266,6 +266,21 @@ class EmbeddingMaintainer(threading.Thread):
"rb", "rb",
) as image_file: ) as image_file:
snapshot_image = image_file.read() 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 = ( embed_image = (
[snapshot_image] [snapshot_image]