Files
Smartwave/orchestrateur/sensors/camera.py
T
Ninluc 7c35b52dbd
Build, push image, and notify Watchtower / build-image (push) Successful in 38s
Build, push image, and notify Watchtower / notify (push) Successful in 11s
Precision in prompt + better camera
2026-08-23 16:48:30 +02:00

49 lines
1.0 KiB
Python

import grovepi
import math
from sensors.lock import grove_lock
from picamera2 import Picamera2, Preview
import time
picam2 = Picamera2()
# Get maximum full-sensor dimensions
sensor_format = picam2.sensor_modes[0]
max_width = sensor_format['size'][0]
max_height = sensor_format['size'][1]
camera_config = picam2.create_still_configuration(
raw={"size": (1640, 1232)},
main={"size": (1640, 1232)}
)
picam2.set_controls({
"AeEnable": True,
"AwbEnable": True,
"ExposureTime": 100000,
"Brightness": 0.30,
"Contrast": 1.1
})
picam2.configure(camera_config)
picam2.start()
time.sleep(2)
def preview_camera():
picam2.start_preview(Preview.DRM)
def stop_preview_camera():
picam2.stop_preview()
def take_picture():
"""Takes a picture and saves it to the file system"""
picam2.capture_file("test.jpg")
return "test.jpg"
def get_picture():
"""Returns the image bytes as base64
"""
file_path = take_picture()
with open(file_path, "rb") as f:
image_bytes = f.read()
return image_bytes