Private
Public Access
working camera movement
This commit is contained in:
1 parent
fce8f62534
commit
11e0875a20
21 files changed
+2117
-334
No files matched your search
+13
-2
@@ -1,5 +1,6 @@
|
||||
"""Ein Kameraproduzent für mehrere Livebild-Betrachter."""
|
||||
|
||||
from collections import deque
|
||||
from io import BytesIO
|
||||
import threading
|
||||
import time
|
||||
@@ -9,6 +10,7 @@ from PIL import Image, ImageDraw
|
||||
|
||||
|
||||
class CameraStream:
|
||||
TARGET_FPS = 15
|
||||
def __init__(self, demo: bool = False):
|
||||
self.demo = demo
|
||||
self._condition = threading.Condition()
|
||||
@@ -16,6 +18,7 @@ class CameraStream:
|
||||
self._stop = threading.Event()
|
||||
self._frame = None
|
||||
self._number = 0
|
||||
self._frame_times = deque(maxlen=45)
|
||||
self._time = None
|
||||
self.error = None
|
||||
|
||||
@@ -43,6 +46,7 @@ class CameraStream:
|
||||
self._frame = frame
|
||||
self._number += 1
|
||||
self._time = time.monotonic()
|
||||
self._frame_times.append(self._time)
|
||||
self._condition.notify_all()
|
||||
|
||||
def _run(self):
|
||||
@@ -75,15 +79,17 @@ class CameraStream:
|
||||
try:
|
||||
# BGR888 liefert laut Picamera2-Dokumentation RGB-Arrays für PIL.
|
||||
config = camera.create_video_configuration(
|
||||
main={"size": (640, 480), "format": "BGR888"}
|
||||
main={"size": (640, 480), "format": "BGR888"},
|
||||
controls={"FrameDurationLimits": (66667, 66667)}, queue=False
|
||||
)
|
||||
camera.configure(config)
|
||||
camera.start()
|
||||
started = True
|
||||
while not self._stop.is_set():
|
||||
began = time.monotonic()
|
||||
pixels = camera.capture_array("main")
|
||||
self._publish(self._jpeg(Image.fromarray(pixels, "RGB")))
|
||||
self._stop.wait(0.2)
|
||||
self._stop.wait(max(0., 1/self.TARGET_FPS-(time.monotonic()-began)))
|
||||
finally:
|
||||
try:
|
||||
if started:
|
||||
@@ -114,7 +120,12 @@ class CameraStream:
|
||||
def status(self):
|
||||
with self._condition:
|
||||
age = None if self._time is None else round(time.monotonic() - self._time, 1)
|
||||
times = self._frame_times
|
||||
fps = ((len(times)-1)/(times[-1]-times[0])
|
||||
if len(times)>1 and times[-1]>times[0] and age is not None and age<1 else 0.)
|
||||
return {
|
||||
"fps": round(fps, 1),
|
||||
"target_fps": 5 if self.demo else self.TARGET_FPS,
|
||||
"source": "Demo" if self.demo else "Pi-Kamera",
|
||||
"ready": self._frame is not None and age is not None and age < 3,
|
||||
"frame_age_seconds": age,
|
||||
|
||||
Reference in new issue
Block a user