Added setup scripts
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
# tools/camera_tool.py
|
||||
from .base_tool import BaseTool
|
||||
import picamera
|
||||
import time
|
||||
import base64
|
||||
from io import BytesIO
|
||||
|
||||
class CameraTool(BaseTool):
|
||||
def get_functions(self):
|
||||
return [{
|
||||
"name": "take_picture",
|
||||
"description": "Take a picture using the Raspberry Pi camera",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {},
|
||||
"required": []
|
||||
}
|
||||
}]
|
||||
|
||||
def execute(self, function_name, **kwargs):
|
||||
if function_name == "take_picture":
|
||||
with picamera.PiCamera() as camera:
|
||||
camera.resolution = (1024, 768)
|
||||
camera.start_preview()
|
||||
# Camera warm-up time
|
||||
time.sleep(2)
|
||||
image_stream = BytesIO()
|
||||
camera.capture(image_stream, 'jpeg')
|
||||
image_stream.seek(0)
|
||||
image_base64 = base64.b64encode(image_stream.getvalue()).decode('utf-8')
|
||||
return f"data:image/jpeg;base64,{image_base64}"
|
||||
Reference in New Issue
Block a user