Caroline Pascal
commited on
fix(camera tool): removing the temporary file creation which was not compatible with Windows. The current solution encodes the frame in the JPG format but stays in the RAM. (#123)
Browse files
src/reachy_mini_conversation_app/tools/camera.py
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
|
|
| 1 |
import asyncio
|
| 2 |
import logging
|
| 3 |
from typing import Any, Dict
|
| 4 |
|
|
|
|
|
|
|
| 5 |
from reachy_mini_conversation_app.tools.core_tools import Tool, ToolDependencies
|
| 6 |
|
| 7 |
|
|
@@ -55,13 +58,11 @@ class Camera(Tool):
|
|
| 55 |
if isinstance(vision_result, str)
|
| 56 |
else {"error": "vision returned non-string"}
|
| 57 |
)
|
| 58 |
-
# Return base64 encoded image like main_works.py camera tool
|
| 59 |
-
import base64
|
| 60 |
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
-
|
| 64 |
-
cv2.imwrite(temp_path, frame)
|
| 65 |
-
with open(temp_path, "rb") as f:
|
| 66 |
-
b64_encoded = base64.b64encode(f.read()).decode("utf-8")
|
| 67 |
return {"b64_im": b64_encoded}
|
|
|
|
| 1 |
+
import base64
|
| 2 |
import asyncio
|
| 3 |
import logging
|
| 4 |
from typing import Any, Dict
|
| 5 |
|
| 6 |
+
import cv2
|
| 7 |
+
|
| 8 |
from reachy_mini_conversation_app.tools.core_tools import Tool, ToolDependencies
|
| 9 |
|
| 10 |
|
|
|
|
| 58 |
if isinstance(vision_result, str)
|
| 59 |
else {"error": "vision returned non-string"}
|
| 60 |
)
|
|
|
|
|
|
|
| 61 |
|
| 62 |
+
# Encode image directly to JPEG bytes without writing to file
|
| 63 |
+
success, buffer = cv2.imencode('.jpg', frame)
|
| 64 |
+
if not success:
|
| 65 |
+
raise RuntimeError("Failed to encode frame as JPEG")
|
| 66 |
|
| 67 |
+
b64_encoded = base64.b64encode(buffer.tobytes()).decode("utf-8")
|
|
|
|
|
|
|
|
|
|
| 68 |
return {"b64_im": b64_encoded}
|