Skip to content

Commit dfa5571

Browse files
authored
Merge pull request #129 from AllenNeuralDynamics/bugfix/camera_connection
Add preventive codes when there is a camera issue (Not filling the frame buffer)
2 parents ee660c0 + eea322f commit dfa5571

File tree

3 files changed

+29
-22
lines changed

3 files changed

+29
-22
lines changed

Diff for: parallax/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import os
66

7-
__version__ = "1.3.0"
7+
__version__ = "1.3.1"
88

99
# allow multiple OpenMP instances
1010
os.environ["KMP_DUPLICATE_LIB_OK"] = "True"

Diff for: parallax/camera.py

+27-20
Original file line numberDiff line numberDiff line change
@@ -495,31 +495,38 @@ def capture(self):
495495
self.last_capture_time = ts
496496

497497
# Retrieve the next image from the camera
498-
image = self.camera.GetNextImage(1000)
499-
500-
while image.IsIncomplete():
501-
time.sleep(0.001)
498+
try:
499+
image = self.camera.GetNextImage(1000)
500+
if image.IsIncomplete():
501+
logger.error(f"Image incomplete: {self.name(sn_only=True)}, Status: {image.GetImageStatus()}")
502+
print(f"{self.name(sn_only=True)} Image incomplete: \n\t{image.GetImageStatus()}")
503+
else:
504+
# Release the previous image from the buffer if it exists
505+
if self.last_image is not None:
506+
self.last_image.Release()
502507

503-
# Release the previous image from the buffer if it exists
504-
if self.last_image is not None:
505-
try:
506-
self.last_image.Release()
507-
except PySpin.SpinnakerException:
508-
print("Spinnaker Exception: Couldn't release last image")
508+
# Update the last captured image reference
509+
self.last_image = image
510+
self.last_image_filled.set()
509511

510-
# Update the last captured image reference
511-
self.last_image = image
512-
self.last_image_filled.set()
512+
except PySpin.SpinnakerException as e:
513+
logger.error(f"{self.name(sn_only=True)} Couldn't get image \n\t{e}")
514+
print(f"{self.name(sn_only=True)} Couldn't get image \n\t{e}")
513515

514-
# Record the image if video recording is active
515-
if self.video_recording_on.is_set():
516-
self.video_recording_idle.clear()
516+
# If video recording is active, record the image
517+
try:
518+
# Record the image if video recording is active
519+
if self.video_recording_on.is_set():
520+
self.video_recording_idle.clear()
517521

518-
frame = self.get_last_image_data()
519-
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
522+
frame = self.get_last_image_data()
523+
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
520524

521-
self.video_output.write(frame)
522-
self.video_recording_idle.set()
525+
self.video_output.write(frame)
526+
self.video_recording_idle.set()
527+
except Exception as e:
528+
logger.error("An error occurred while recording the video: ", e)
529+
print(f"Error {self.name(sn_only=True)}: An error occurred while recording the video.")
523530

524531
def get_last_capture_time(self, millisecond=False):
525532
"""

Diff for: parallax/stage_listener.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
# Set logger name
1919
logger = logging.getLogger(__name__)
20-
logger.setLevel(logging.DEBUG)
20+
logger.setLevel(logging.WARNING)
2121
package_dir = os.path.dirname(os.path.abspath(__file__))
2222

2323

0 commit comments

Comments
 (0)