feat: implement camera management with GPhotoCamera and CameraManager classes

This commit is contained in:
2025-09-21 08:38:26 +02:00
parent 2187536c7d
commit 508930ae39
5 changed files with 177 additions and 4 deletions

View File

@@ -0,0 +1,46 @@
import gphoto2 as gp
import cv2
import numpy as np
from .base_camera import BaseCamera
class GPhotoCamera(BaseCamera):
def __init__(self) -> None:
super().__init__()
self.camera = None
def connect(self) -> bool:
self.error_msg = None
try:
self.camera = gp.Camera() # type: ignore
self.camera.init()
return True
except Exception as e:
self.error_msg = f"[GPHOTO2] {e}"
self.camera = None
return False
def disconnect(self) -> None:
if self.camera:
self.camera.exit()
self.camera = None
def get_frame(self):
self.error_msg = None
if self.camera is None:
self.error_msg = "[GPHOTO2] Camera is not initialized."
return (False, None)
try:
file = self.camera.capture_preview() # type: ignore
data = file.get_data_and_size()
frame = np.frombuffer(data, dtype=np.uint8)
frame = cv2.imdecode(frame, cv2.IMREAD_COLOR)
return (True, frame)
except Exception as e:
self.error_msg = f"[GPHOTO2] {e}"
return (False, None)