From d9a0510d6f20febfc771fbc9dfaa040b669061dd Mon Sep 17 00:00:00 2001 From: mgineer85 Date: Wed, 30 Oct 2024 13:17:26 +0100 Subject: [PATCH] refactor --- node/services/backends/cameras/picamera2.py | 29 ++++++--------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/node/services/backends/cameras/picamera2.py b/node/services/backends/cameras/picamera2.py index f3d83c5..853358c 100644 --- a/node/services/backends/cameras/picamera2.py +++ b/node/services/backends/cameras/picamera2.py @@ -202,12 +202,12 @@ def clamp(n, min_value, max_value): def recover(self): tms = time.time() - for _ in range(2): # 2 is size of buffer so tick->clear no processing. - pass - ## self._event_request_tick.wait(timeout=2.0) - self._queue_timestamp_monotonic_ns.get(block=True, timeout=2) - self._queue_camera_timestamp_ns.get(block=True, timeout=2) - ## self._picamera2.drop_frames(1, wait=True) # on start drop all old frames... + for _ in range(4): # 2 is size of buffer so tick->clear no processing. + try: + self._queue_timestamp_monotonic_ns.get(block=True, timeout=2.0) + self._queue_camera_timestamp_ns.get(block=True, timeout=2.0) + except Exception: + pass logger.info(f"recovered, time taken: {round((time.time() - tms)*1.0e3, 0)}ms") @@ -279,35 +279,22 @@ def _camera_fun(self): logger.debug("starting _camera_fun") while not current_thread().stopped(): - job = self._picamera2.capture_request(wait=False) - - try: - request = self._picamera2.wait(job, timeout=2.0) - except TimeoutError: # no information in exc avail so omitted - logger.warning("timeout while waiting for clock/camera") - # break thread run loop, so the function will quit and .alive is false for this thread - - # supervisor could then decide to start it again. - break - if self._capture.is_set(): self._capture.clear() self._capture_in_progress = True tms = time.time() - self._queue_processing.put(request.make_buffer("main")) - time.sleep(0.5) + self._queue_processing.put(self._picamera2.capture_buffer("main", wait=2.0)) logger.info(f"queued up buffer to process image, time taken: {round((time.time() - tms)*1.0e3, 0)}ms") self._capture_in_progress = False else: - picam_metadata = request.get_metadata() + picam_metadata = self._picamera2.capture_metadata(wait=2.0) try: self._queue_camera_timestamp_ns.put_nowait(picam_metadata["SensorTimestamp"]) except Full: logger.warning("could not queue camera timestamp!") - request.release() - logger.info("_camera_fun left") def _processing_fun(self):