def detect_cameras(self): """Detects number of cameras of each type""" num_attempts = 10 # We'll try to detect up to 10 cameras # -- Try to detect PT Grey Firefly Cameras -- # temp_ff_context = fc.Context() for i in range(num_attempts): try: temp_ff_context.get_camera_from_index(i) self.cameras.append((FireFly_Camera, i)) num_attempts -= 1 except fc.ApiError: pass temp_ff_context.disconnect() # -- Try to detect Mini Microscopes -- # # Disable extraneous error messages devnull = open(os.devnull, 'w') stderr = sys.stderr sys.stderr = devnull # Check for mini microscopes for i in range(num_attempts): try: cam = xi.Xi_Camera(DevID=i) cam.get_image() cam.close() self.cameras.append((Mini_Microscope, i)) num_attempts -= 1 except (xi.XI_Error, xi.ximea.XI_Error): print('xi error', i) # Reinstate Error Messages sys.stderr = stderr devnull.close() # Finalize number of cameras across processes self.num_cmrs = len(self.cameras)
def init_ff_camera(self): """Initializes a PT Grey FireFly""" try: self.fc_context = fc.Context() self.fc_context.connect( *self.fc_context.get_camera_from_index(self.cmr_id)) self.fc_context.set_video_mode_and_frame_rate( fc.VIDEOMODE_640x480Y8, fc.FRAMERATE_30) self.fc_context.set_property( **self.fc_context.get_property(fc.FRAME_RATE)) self.fc_context.start_capture() except self.camera_error: self.connected = False else: self.connected = True
def init_firefly_camera(self): """Initializes a PT Grey Firefly Camera""" try: self.fc_context = fc.Context() self.fc_context.connect( *self.fc_context.get_camera_from_index(self.cmr_id)) self.fc_context.set_video_mode_and_frame_rate( fc.VIDEOMODE_640x480Y8, fc.FRAMERATE_30) self.fc_context.set_property( **self.fc_context.get_property(fc.FRAME_RATE)) self.fc_context.start_capture() # self.status_queue.put_nowait('<cmr>Connected to Camera!') self.connected = True except self.camera_error: # self.status_queue.put_nowait('<cmr>** Camera is disconnected or occupied by another program. ' # 'Please disconnect and try again.') self.connected = False
def initialize(self): """checks that camera is available""" try: self.context = fc2.Context() self.context.connect(*self.context.get_camera_from_index(0)) self.context.set_video_mode_and_frame_rate(fc2.VIDEOMODE_640x480Y8, fc2.FRAMERATE_30) self.context.set_property( **self.context.get_property(fc2.FRAME_RATE)) self.context.start_capture() self.status_queue.put_nowait('<cmr>Connected to Camera!') self.connected = True return True except fc2.ApiError: self.status_queue.put_nowait('<cmr>** Camera is not connected or' ' is occupied by another program. ' 'Please disconnect and try again.') self.connected = False return False
def detect_cameras(self): """Detects number of cameras of each type""" num_attempts = 10 # We look for up to 10 TOTAL cameras (all types combined) cameras = [] # -- Detect PTGrey Fireflies -- # temp_ff_context = fc.Context() for cmr_id in range(num_attempts): try: temp_ff_context.get_camera_from_index(cmr_id) except fc.ApiError: pass else: cameras.append((FIREFLY_CAMERA, cmr_id)) num_attempts -= 1 temp_ff_context.disconnect() # -- Detect Ximea Cameras -- # # Disable erroneous error messages devnull = open(os.devnull, 'w') stderr = sys.stderr sys.stderr = devnull # Check for ximea cameras for cmr_id in range(num_attempts): try: cam = xi.Xi_Camera(DevID=cmr_id) cam.get_image() cam.close() except (xi.XI_Error, xi.ximea.XI_Error): pass else: cameras.append((MINIMIC_CAMERA, cmr_id)) num_attempts -= 1 # Re-enable error messages sys.stderr = stderr devnull.close() # Finalize total num cameras self.num_cmrs = len(cameras) # Create Cameras for stream_index, (cmr_type, cmr_id) in enumerate(cameras): self.cameras[stream_index] = SingleCameraWidget(self.dirs, stream_index, cmr_type, cmr_id)