Ejemplo n.º 1
0
    def __init__(self):
        #variables
        self.FILECOUNTER = 0
        self.counter = 0  # 0 = background Image ; 1 = wave Image
        self.singleTriggerMode = True
        self.maxIntensity = 65536
        self.minIntensity = 0

        #open camera and setup settings:
        self.sdk = TLCameraSDK()
        cameras = self.sdk.discover_available_cameras()
        if len(cameras) == 0:
            print("Error: no cameras detected!")

        self.camera = self.sdk.open_camera(cameras[0])
        self.camera.frames_per_trigger_zero_for_unlimited = 1
        self.camera.operation_mode = OPERATION_MODE.BULB  # set Hardwaretrigger
        self.camera.trigger_polarity = TRIGGER_POLARITY.ACTIVE_HIGH  # Trigger auf active HIGH
        #self.camera.exposure_time_us = 10
        print("Exposure Time :", self.camera.exposure_time_us)
        print("Bit Depth: ", self.camera.bit_depth)
        print(self.camera.operation_mode)
        print(self.camera.trigger_polarity)
        self.camera.image_poll_timeout_ms = 1000  # 1 second timeout
        self.camera.arm(2)
Ejemplo n.º 2
0
    def connect(self, sn):
        """Connect to the camera with the given serial number.

        :param str sn: Camera serial number.
        """
        self.sdk = TLCameraSDK()
        self.camera = self.sdk.open_camera(sn)

        self._sn = self.camera.serial_number
        self._model = self.camera.model

        self._swidth = self.camera.sensor_width_pixels
        self._sheight = self.camera.sensor_height_pixels
        self._rgb = (self.camera.camera_sensor_type == 1)
        self._bitsperpixel = self.camera.bit_depth
        logger.info(
            ("Sensor: %d x %d pixels, RGB = %d, %d bits/px" %
             (self._swidth, self._sheight, self._rgb, self._bitsperpixel)))

        self.camera.operation_mode = 0  # software-triggered
        self.camera.frames_per_trigger_zero_for_unlimited = 1  # single frame per trigger
        self.camera.is_frame_rate_control_enabled = False  # disable frame rate control

        self.fpsmin = self.camera.frame_rate_control_value_range.min  # min fps
        self.fpsmax = self.camera.frame_rate_control_value_range.max  # max fps

        self.expmin = self.camera.exposure_time_range_us.min / 1000.  # exposure min in ms
        self.expmax = self.camera.exposure_time_range_us.max / 1000.  # exposure max in ms
        logger.info(("Valid exposure times: %fms to %fms" %
                     (self.expmin, self.expmax)))
        self.set_exposure(self.expmin)  # set exposure to min value

        self.camera.image_poll_timeout_ms = 5000  # 5 second polling timeout

        self.camera.arm(2)  # arm the camera with a two-frame buffer
Ejemplo n.º 3
0
 def get_cameras(self):
     """Finds the connected TSI cameras.
     """
     with TLCameraSDK() as sdk:
         available_cameras = sdk.discover_available_cameras()
     nCams = len(available_cameras)
     logger.info(("Found %d tsi camera(s)" % nCams))
     if nCams > 0:
         self._cam_list = available_cameras
Ejemplo n.º 4
0
 def __init__(self):
     self.camSesh = TLCameraSDK()
     camList = self.camSesh.discover_available_cameras()
     camSerialNum = '08153'
     self.cam = self.camSesh.open_camera(camSerialNum)
     self.cam.operation_mode = thorlabs_tsi_sdk.tl_camera_enums.OPERATION_MODE.SOFTWARE_TRIGGERED
     # Set camera exposure in units of microseconds
     expose_time = 36
     self.cam.exposure_time_us = expose_time
     self.cam.frames_per_trigger_zero_for_unlimited = 1
     self.isStreaming = False
Ejemplo n.º 5
0
    def activate(self,quiet=False):
        
        # begin camera id block
        self.userChoseStream = False
        validCamRange = [None, None]
        
        self.camera_sdk = TLCameraSDK()
        self.mono_to_color_sdk = MonoToColorProcessorSDK()
        
        try:
            self.available_cameras = self.camera_sdk.discover_available_cameras()
        except UnicodeDecodeError:
            cprint("Thorlabs SDK Error: Please power cycle camera",'red',attrs=['bold'])
            exit()
            
        if len(self.available_cameras) < 1:
            cprint("no cameras detected! Check udev rules",'red',attrs=['bold'])
            return
        elif len(self.available_cameras) > 1:
            for i in range(len(self.available_cameras)):
                print("%i: %s" % (i,self.available_cameras[i]))
            while not self.params['ID'] in validCamRange:
                try:
                    self.params['ID']=int(raw_input("\tPlease select camera ID [0-%i]:" % (len(self.available_cameras)-1)))
                    self.userChoseStream = True
                except:
                    pass
        else:
            self.params['ID']=0
        
        # End camera id block
        
        # Set up configuration for number of frames to capture per query event
        
        if 'n_frames' in self.params: self.config['n_frames'] = self.params['n_frames']
        else: self.config['n_frames'] = 1
        
        # Make first query to get units, description, etc.
        self.query(reset=True)

        if not quiet: self.pprint()
        return
Ejemplo n.º 6
0
    def __init__(self, timeout=500):
        self.sdk = TLCameraSDK()
        cameralist = self.sdk.discover_available_cameras()
        if len(cameralist) == 0:
            print("Error: no cameras detected!")

        self.camera = self.sdk.open_camera(cameralist[0])
        #  setup the camera for continuous acquisition
        self.camera.frames_per_trigger_zero_for_unlimited = 0
        self.camera.image_poll_timeout_ms = 2000  # 2 second timeout
        self.camera.arm(2)
        self.camera.exposure_time_us = 100

        # save these values to place in our custom TIFF tags later
        bit_depth = self.camera.bit_depth
        exposure = self.camera.exposure_time_us

        # need to save the image width and height for color processing
        image_width = self.camera.image_width_pixels
        image_height = self.camera.image_height_pixels
        print(image_width)
        print(image_height)
        self.image = None
from thorlabs_tsi_sdk.tl_mono_to_color_processor import MonoToColorProcessorSDK
from thorlabs_tsi_sdk.tl_camera_enums import SENSOR_TYPE

NUMBER_OF_IMAGES = 10  # Number of TIFF images to be saved
OUTPUT_DIRECTORY = os.path.abspath(
    r'.')  # Directory the TIFFs will be saved to
FILENAME = 'image.tif'  # The filename of the TIFF

TAG_BITDEPTH = 32768
TAG_EXPOSURE = 32769

# delete image if it exists
if os.path.exists(OUTPUT_DIRECTORY + os.sep + FILENAME):
    os.remove(OUTPUT_DIRECTORY + os.sep + FILENAME)

with TLCameraSDK() as sdk:
    cameras = sdk.discover_available_cameras()
    if len(cameras) == 0:
        print("Error: no cameras detected!")

    with sdk.open_camera(cameras[0]) as camera:
        #  setup the camera for continuous acquisition
        camera.frames_per_trigger_zero_for_unlimited = 0
        camera.image_poll_timeout_ms = 2000  # 2 second timeout
        camera.arm(2)

        # save these values to place in our custom TIFF tags later
        bit_depth = camera.bit_depth
        exposure = camera.exposure_time_us

        # need to save the image width and height for color processing
Ejemplo n.º 8
0
 def __init__(self):
     self.camera_sdk = TLCameraSDK()
     self.discover_cameras()
     self.mono2color_sdk = MonoToColorProcessorSDK()
Ejemplo n.º 9
0
    # if on Windows, use the provided setup script to add the DLLs folder to the PATH
    from examples.windows_setup import configure_path
    configure_path()
except ImportError:
    configure_path = None

from thorlabs_tsi_sdk.tl_camera import TLCameraSDK
from thorlabs_tsi_sdk.tl_mono_to_color_processor import MonoToColorProcessorSDK
from thorlabs_tsi_sdk.tl_mono_to_color_enums import COLOR_SPACE
from thorlabs_tsi_sdk.tl_color_enums import FORMAT
"""
    The MonoToColorProcessorSDK and MonoToColorProcessor objects can be used with context managers for automatic 
    clean up. This multi-context-manager 'with' statement opens both the camera sdk and the mono to color sdk at 
    once. 
"""
with TLCameraSDK() as camera_sdk, MonoToColorProcessorSDK(
) as mono_to_color_sdk:
    available_cameras = camera_sdk.discover_available_cameras()
    if len(available_cameras) < 1:
        raise ValueError("no cameras detected")

    with camera_sdk.open_camera(available_cameras[0]) as camera:
        camera.frames_per_trigger_zero_for_unlimited = 0  # start camera in continuous mode
        camera.image_poll_timeout_ms = 2000  # 2 second timeout
        camera.arm(2)
        """
            In a real-world scenario, we want to save the image width and height before color processing so that we 
            do not have to query it from the camera each time it is needed, which would slow down the process. It is 
            safe to save these after arming since the image width and height cannot change while the camera is armed.
        """
        image_width = camera.image_width_pixels