From 4b2d9a0fa6d5c244efc53c3e8b40f3ec2121500d Mon Sep 17 00:00:00 2001 From: gemblerz Date: Wed, 31 May 2023 11:15:31 -0500 Subject: [PATCH] Timestamp Camera images between grab and decode (#36) --- src/waggle/data/vision.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/waggle/data/vision.py b/src/waggle/data/vision.py index a1700df..fe69b24 100644 --- a/src/waggle/data/vision.py +++ b/src/waggle/data/vision.py @@ -144,16 +144,22 @@ def __exit__(self, exc_type, exc_val, exc_tb): self.capture.release() def snapshot(self): - timestamp = get_timestamp() - ok, data = self.capture.read() + ok = self.capture.grab() if not ok: raise RuntimeError("failed to take snapshot") + timestamp = get_timestamp() + ok, data = self.capture.retrieve() + if not ok: + raise RuntimeError("failed to retrieve the taken snapshot") return ImageSample(data=data, timestamp=timestamp, format=self.format) def stream(self): while True: + ok = self.capture.grab() + if not ok: + break timestamp = get_timestamp() - ok, data = self.capture.read() + ok, data = self.capture.retrieve() if not ok: break yield ImageSample(data=data, timestamp=timestamp, format=self.format)