Skip to content

Add preventive codes when there is a camera connection issue #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion parallax/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import os

__version__ = "1.3.0"
__version__ = "1.3.1"

# allow multiple OpenMP instances
os.environ["KMP_DUPLICATE_LIB_OK"] = "True"
47 changes: 27 additions & 20 deletions parallax/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,31 +495,38 @@ def capture(self):
self.last_capture_time = ts

# Retrieve the next image from the camera
image = self.camera.GetNextImage(1000)

while image.IsIncomplete():
time.sleep(0.001)
try:
image = self.camera.GetNextImage(1000)
if image.IsIncomplete():
logger.error(f"Image incomplete: {self.name(sn_only=True)}, Status: {image.GetImageStatus()}")
print(f"{self.name(sn_only=True)} Image incomplete: \n\t{image.GetImageStatus()}")
else:
# Release the previous image from the buffer if it exists
if self.last_image is not None:
self.last_image.Release()

# Release the previous image from the buffer if it exists
if self.last_image is not None:
try:
self.last_image.Release()
except PySpin.SpinnakerException:
print("Spinnaker Exception: Couldn't release last image")
# Update the last captured image reference
self.last_image = image
self.last_image_filled.set()

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

# Record the image if video recording is active
if self.video_recording_on.is_set():
self.video_recording_idle.clear()
# If video recording is active, record the image
try:
# Record the image if video recording is active
if self.video_recording_on.is_set():
self.video_recording_idle.clear()

frame = self.get_last_image_data()
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
frame = self.get_last_image_data()
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)

self.video_output.write(frame)
self.video_recording_idle.set()
self.video_output.write(frame)
self.video_recording_idle.set()
except Exception as e:
logger.error("An error occurred while recording the video: ", e)
print(f"Error {self.name(sn_only=True)}: An error occurred while recording the video.")

def get_last_capture_time(self, millisecond=False):
"""
Expand Down
2 changes: 1 addition & 1 deletion parallax/stage_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

# Set logger name
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logger.setLevel(logging.WARNING)
package_dir = os.path.dirname(os.path.abspath(__file__))


Expand Down
Loading