Skip to content

Commit

Permalink
Fix first frame dropping
Browse files Browse the repository at this point in the history
  • Loading branch information
THD2-team authored and ivalaginja committed Apr 25, 2024
1 parent df1f853 commit 3594b19
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions catkit2/services/hamamatsu_camera/hamamatsu_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,21 +202,25 @@ def acquisition_loop(self):

timeout_millisec = 2000
try:
i = 0
while self.should_be_acquiring.is_set() and not self.should_shut_down:
if self.cam.lasterr().is_timeout():
self.log.warning('Timeout while waiting for frame')
if self.cam.wait_capevent_frameready(timeout_millisec) is False:
raise RuntimeError(f'Dcam.wait_capevent_frameready({timeout_millisec}) fails with error {self.cam.lasterr()}')

if self.cam.buf_getframedata(-2) is False:
# If there is no second to last frame, it means we just acquired the first frame.
# In this case, drop the current frame since it always contains systematic errors.
img = self.cam.buf_getlastframedata()

if i == 0:
# The first frame often contains systematic errors, so drop it.
self.log.info('Dropping first camera frame')
i += 1
continue

img = self.cam.buf_getlastframedata()
self.images.submit_data(img.astype('float32'))

i += 1

finally:
# Stop acquisition.
self.cam.cap_stop()
Expand Down

0 comments on commit 3594b19

Please sign in to comment.