- Discover libcamera cameras, falling back to V4L2; label them Back, Front or External and pick the rear sensor first - Photo mode: JPEG saves to ~/Pictures/Camera, with an optional high-res still capture - Video mode: H.264 MP4 recording through ffmpeg, saved to ~/Videos/Camera - Rear torch LED toggle via sysfs, falling back to logind SetBrightness - GTK3 + Cairo Wayland UI with a viewfinder, timer, grid, camera switch and gallery view - Add the desktop entry, icon and camera tests
This commit is contained in:
1 parent
74235cb0ca
commit
1c954aa657
10 files changed
+3479
-8
No files matched your search
+24
-7
@@ -439,10 +439,16 @@ def query_camera(path):
|
||||
os.close(fd)
|
||||
|
||||
|
||||
def _import_libcamera():
|
||||
os.environ.setdefault("LIBCAMERA_LOG_LEVELS", "*:ERROR")
|
||||
import libcamera
|
||||
return libcamera
|
||||
|
||||
|
||||
def list_libcameras():
|
||||
"""[(libcamera:id, label, '')] for cameras exposed through libcamera."""
|
||||
try:
|
||||
import libcamera
|
||||
libcamera = _import_libcamera()
|
||||
except ImportError:
|
||||
return []
|
||||
out = []
|
||||
@@ -484,7 +490,7 @@ def camera_problem(device):
|
||||
if device.startswith("libcamera:"):
|
||||
cid = device[len("libcamera:"):]
|
||||
try:
|
||||
import libcamera
|
||||
libcamera = _import_libcamera()
|
||||
except ImportError:
|
||||
return "python-libcamera is not installed (cannot open %s)" % device
|
||||
cm = libcamera.CameraManager.singleton()
|
||||
@@ -511,11 +517,13 @@ class LibcameraCamera:
|
||||
if problem:
|
||||
raise Fail(problem, 2)
|
||||
import cv2
|
||||
import libcamera
|
||||
import mmap
|
||||
import numpy as np
|
||||
libcamera = _import_libcamera()
|
||||
|
||||
self.cv2, self.libcamera, self.mmap, self.np = cv2, libcamera, mmap, np
|
||||
reuse_enum = getattr(libcamera.Request, "Reuse", None) or getattr(libcamera.Request, "ReuseFlag", None)
|
||||
self._reuse_arg = getattr(reuse_enum, "ReuseBuffers", None) if reuse_enum is not None else None
|
||||
cid = device[len("libcamera:"):]
|
||||
self.cm = libcamera.CameraManager.singleton()
|
||||
self.cam = self.cm.get(cid)
|
||||
@@ -573,6 +581,17 @@ class LibcameraCamera:
|
||||
return self.cv2.rotate(bgr, self.cv2.ROTATE_90_COUNTERCLOCKWISE)
|
||||
return bgr
|
||||
|
||||
def _requeue(self, req):
|
||||
if self._reuse_arg is not None:
|
||||
try:
|
||||
req.reuse(self._reuse_arg)
|
||||
except TypeError:
|
||||
self._reuse_arg = None
|
||||
req.reuse()
|
||||
else:
|
||||
req.reuse()
|
||||
self.cam.queue_request(req)
|
||||
|
||||
def read(self):
|
||||
timeout = 3.0 if self._first else 1.5
|
||||
self._first = False
|
||||
@@ -581,16 +600,14 @@ class LibcameraCamera:
|
||||
ready = self.cm.get_ready_requests()
|
||||
if ready:
|
||||
for old in ready[:-1]:
|
||||
old.reuse(self.libcamera.Request.ReuseFlag.ReuseBuffers)
|
||||
self.cam.queue_request(old)
|
||||
self._requeue(old)
|
||||
req = ready[-1]
|
||||
frame = None
|
||||
try:
|
||||
if req.status == self.libcamera.Request.Status.Complete:
|
||||
frame = self._to_bgr(req.buffers[self.sc.stream])
|
||||
finally:
|
||||
req.reuse(self.libcamera.Request.ReuseFlag.ReuseBuffers)
|
||||
self.cam.queue_request(req)
|
||||
self._requeue(req)
|
||||
if frame is not None:
|
||||
return frame
|
||||
time.sleep(0.01)
|
||||
|
||||
Reference in new issue
Block a user