Skip to content

Commit

Permalink
improve capture in sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
mgineer85 committed Nov 4, 2024
1 parent 009f57d commit 14e7f42
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
8 changes: 7 additions & 1 deletion wigglecam/services/backends/cameras/abstractbackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,15 @@ def wait_for_lores_image(self) -> bytes:
def wait_for_hires_frame(self):
pass

@abstractmethod
def done_hires_frames(self):
pass

@abstractmethod
def wait_for_hires_image(self, format: str) -> bytes:
return self.encode_frame_to_image(self.wait_for_hires_frame(), format)
out = self.encode_frame_to_image(self.wait_for_hires_frame(), format)
self.done_hires_frames() # means with direct encoding this is really only for one-time shots, otherwise better wait_for_hires_frames
return out

@abstractmethod
def encode_frame_to_image(self, frame, format: str) -> bytes:
Expand Down
7 changes: 5 additions & 2 deletions wigglecam/services/backends/cameras/picamera2.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,12 @@ def wait_for_hires_frame(self):
if not self._hires_data.condition.wait(timeout=2.0):
raise TimeoutError("timeout receiving frames")

self._hires_data.request_hires_still.clear()
# self._hires_data.request_hires_still.clear()
return self._hires_data.frame

def done_hires_frames(self):
self._hires_data.request_hires_still.clear()

def wait_for_hires_image(self, format: str) -> bytes:
return super().wait_for_hires_image(format=format)

Expand Down Expand Up @@ -276,7 +279,7 @@ def _camera_fun(self):
while not current_thread().stopped():
if self._hires_data.request_hires_still.is_set():
# only capture one pic and return, overlying classes are responsible to ask again if needed fast enough
self._hires_data.request_hires_still.clear()
# self._hires_data.request_hires_still.clear()

# capture hq picture
with self._picamera2.captured_request(wait=1.5) as request:
Expand Down
3 changes: 3 additions & 0 deletions wigglecam/services/backends/cameras/virtualcamera.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ def wait_for_hires_frame(self):
def wait_for_hires_image(self, format: str):
return super().wait_for_hires_image(format=format)

def done_hires_frames(self):
pass

def encode_frame_to_image(self, frame, format: str) -> bytes:
# for virtualcamera frame == jpeg data, so no convertion needed.
if format == "jpeg":
Expand Down

0 comments on commit 14e7f42

Please sign in to comment.