Exemple #1
0
def Multiple_cameras_acquisition_thread(label1, label2):
    system = PySpin.System.GetInstance()
    cam_list = system.GetCameras()
    num_cameras = cam_list.GetSize()
    print('Number of cameras detected: %d' % num_cameras)
    # Finish if there are no cameras
    if num_cameras == 0:
        # Clear camera list before releasing system
        cam_list.Clear()
        # Release system instance
        system.ReleaseInstance()
        print('Not enough cameras!')
    for i, cam in enumerate(cam_list):
        # Initialize camera
        cam.Init()
    for i, cam in enumerate(cam_list):
        # Set acquisition mode to continuous
        node_acquisition_mode = PySpin.CEnumerationPtr(
            cam.GetNodeMap().GetNode('AcquisitionMode'))
        if not PySpin.IsAvailable(
                node_acquisition_mode) or not PySpin.IsWritable(
                    node_acquisition_mode):
            print(
                'Unable to set acquisition mode to continuous (node retrieval; camera %d). Aborting... \n'
                % i)
            return False
        node_acquisition_mode_continuous = node_acquisition_mode.GetEntryByName(
            'Continuous')
        if not PySpin.IsAvailable(
                node_acquisition_mode_continuous) or not PySpin.IsReadable(
                    node_acquisition_mode_continuous):
            print(
                'Unable to set acquisition mode to continuous (entry \'continuous\' retrieval %d). \
            Aborting... \n' % i)
            return False
        acquisition_mode_continuous = node_acquisition_mode_continuous.GetValue(
        )
        node_acquisition_mode.SetIntValue(acquisition_mode_continuous)
        print('Camera %d acquisition mode set to continuous...' % i)
        # Begin acquiring images
        cam.BeginAcquisition()

    while True:
        for i, cam in enumerate(cam_list):
            image_result = cam.GetNextImage()
            h = image_result.GetHeight()
            w = image_result.GetWidth()
            convertToQtFormat = QtGui.QImage(image_result.GetData(), w, h,
                                             QtGui.QImage.Format_Grayscale8)
            if i == 0:
                label1.setPixmap(QPixmap.fromImage(convertToQtFormat))
            else:
                label2.setPixmap(QPixmap.fromImage(convertToQtFormat))
        time.sleep(0.001)
    def set_feature(self, nodemap, node_name, feature_name, value):
        '''
        method to get any stt from a camera
        
        nodemap: the node map of a collection of camera properties,
                e.g. TLDEVICE
        
        node_name: Name of the specific node, such as DeviceInformation
        
        feature_name: Name of the specific feature, such as ModelNumber
        '''
        try:
            node = PySpin.CCategoryPtr(nodemap.GetNode(node_name))
            if PySpin.IsAvailable(node) and PySpin.IsReadable(node):
                features = node.GetFeatures()
                for feature in features:
                    node_feature = PySpin.CValuePtr(feature)
                    if node_feature.GetName() == feature_name:
                        node_feature.FromString(value)

            else:
                print('No feature named %s found' % feature_name)
                return None
        except PySpin.SpinnakerException as ex:
            print("Error: %s" % ex)
 def get_height(self):
     try:
         node_height = PySpin.CIntegerPtr(self.nodemap.GetNode("Height"))
         if PySpin.IsAvailable(node_height):
             return node_height.GetValue()
     except PySpin.SpinnakerException as ex:
         print("Error: %s" % ex)
 def get_width(self):
     try:
         node_width = PySpin.CIntegerPtr(self.nodemap.GetNode("Width"))
         if PySpin.IsAvailable(node_width):
             return node_width.GetValue()
     except PySpin.SpinnakerException as ex:
         print("Error: %s" % ex)
Exemple #5
0
def run_multiple_cameras_modified(cam_list):
    print('6')
    result = True
    for i, cam in enumerate(cam_list):
        print('7')
        # Retrieve TL device nodemap
        nodemap_tldevice = cam.GetTLDeviceNodeMap()
        # Print device information
        # result &= print_device_info(nodemap_tldevice, i)
        for i, cam in enumerate(cam_list):
            # Initialize camera
            cam.Init()
        for i, cam in enumerate(cam_list):
            # Set acquisition mode to continuous
            node_acquisition_mode = PySpin.CEnumerationPtr(
                cam.GetNodeMap().GetNode('AcquisitionMode'))
            if not PySpin.IsAvailable(
                    node_acquisition_mode) or not PySpin.IsWritable(
                        node_acquisition_mode):
                print(
                    'Unable to set acquisition mode to continuous (node retrieval; camera %d). Aborting... \n'
                    % i)
                return False
            node_acquisition_mode_continuous = node_acquisition_mode.GetEntryByName(
                'Continuous')
            if not PySpin.IsAvailable(
                    node_acquisition_mode_continuous) or not PySpin.IsReadable(
                        node_acquisition_mode_continuous):
                print(
                    'Unable to set acquisition mode to continuous (entry \'continuous\' retrieval %d). \
                Aborting... \n' % i)
                return False
            acquisition_mode_continuous = node_acquisition_mode_continuous.GetValue(
            )

            node_acquisition_mode.SetIntValue(acquisition_mode_continuous)
            print('Camera %d acquisition mode set to continuous...' % i)
            # Begin acquiring images
            cam.BeginAcquisition()
    def start(self):
        '''
        Start the continuous acquisition mode
        '''
        try:
            #get handle for acquisition mode
            node_acquisition_mode = PySpin.CEnumerationPtr(
                self.nodemap.GetNode("AcquisitionMode"))
            if not PySpin.IsAvailable(
                    node_acquisition_mode) or not PySpin.IsWritable(
                        node_acquisition_mode):
                print(
                    "Unable to set acquisition mode to continuous (enum retrieval). Aborting..."
                )
                return False

            # Retrieve entry node from enumeration node
            node_acquisition_mode_continuous = node_acquisition_mode.GetEntryByName(
                "Continuous")
            if not PySpin.IsAvailable(
                    node_acquisition_mode_continuous) or not PySpin.IsReadable(
                        node_acquisition_mode_continuous):
                print(
                    "Unable to set acquisition mode to continuous (entry retrieval). Aborting..."
                )
                return False

            # Retrieve integer value from entry node
            acquisition_mode_continuous = node_acquisition_mode_continuous.GetValue(
            )

            # Set integer value from entry node as new value of enumeration node
            node_acquisition_mode.SetIntValue(acquisition_mode_continuous)

            #Begin Acquisition
            self.cam.BeginAcquisition()

        except PySpin.SpinnakerException as ex:
            print("Error: %s" % ex)
def print_device_info(nodemap, cam_num):
    """
    This function prints the device information of the camera from the transport
    layer; please see NodeMapInfo example for more in-depth comments on printing
    device information from the nodemap.

    :param nodemap: Transport layer device nodemap.
    :param cam_num: Camera number.
    :type nodemap: INodeMap
    :type cam_num: int
    :returns: True if successful, False otherwise.
    :rtype: bool
    """

    print('Printing device information for camera %d... \n' % cam_num)

    try:
        result = True
        node_device_information = PySpin.CCategoryPtr(
            nodemap.GetNode('DeviceInformation'))

        if PySpin.IsAvailable(node_device_information) and PySpin.IsReadable(
                node_device_information):
            features = node_device_information.GetFeatures()
            for feature in features:
                node_feature = PySpin.CValuePtr(feature)
                print(
                    '%s: %s' %
                    (node_feature.GetName(), node_feature.ToString() if
                     PySpin.IsReadable(node_feature) else 'Node not readable'))

        else:
            print('Device control information not available.')
        print()

    except PySpin.SpinnakerException as ex:
        print('Error: %s' % ex)
        return False

    return result
    def get_model(self):
        """
        This function get the model name
        """
        try:
            node_device_information = PySpin.CCategoryPtr(
                self.nodemap_tldevice.GetNode("DeviceInformation"))

            if PySpin.IsAvailable(
                    node_device_information) and PySpin.IsReadable(
                        node_device_information):
                features = node_device_information.GetFeatures()
                for feature in features:
                    node_feature = PySpin.CValuePtr(feature)
                    if node_feature.GetName() == 'DeviceModelName':
                        return node_feature.ToString()

            else:
                return 'N/A'

        except PySpin.SpinnakerException as ex:
            print("Error: %s" % ex)
            return 'N/A'
def acquire_images(cam_list):
    """
    This function acquires and saves 10 images from each device.

    :param cam_list: List of cameras
    :type cam_list: CameraList
    :return: True if successful, False otherwise.
    :rtype: bool
    """

    print('*** IMAGE ACQUISITION ***\n')
    try:
        result = True

        # Prepare each camera to acquire images
        #
        # *** NOTES ***
        # For pseudo-simultaneous streaming, each camera is prepared as if it
        # were just one, but in a loop. Notice that cameras are selected with
        # an index. We demonstrate pseduo-simultaneous streaming because true
        # simultaneous streaming would require multiple process or threads,
        # which is too complex for an example.
        #

        for i, cam in enumerate(cam_list):

            # Set acquisition mode to continuous
            node_acquisition_mode = PySpin.CEnumerationPtr(
                cam.GetNodeMap().GetNode('AcquisitionMode'))
            if not PySpin.IsAvailable(
                    node_acquisition_mode) or not PySpin.IsWritable(
                        node_acquisition_mode):
                print(
                    'Unable to set acquisition mode to continuous (node retrieval; camera %d). Aborting... \n'
                    % i)
                return False

            node_acquisition_mode_continuous = node_acquisition_mode.GetEntryByName(
                'Continuous')
            if not PySpin.IsAvailable(
                    node_acquisition_mode_continuous) or not PySpin.IsReadable(
                        node_acquisition_mode_continuous):
                print(
                    'Unable to set acquisition mode to continuous (entry \'continuous\' retrieval %d). \
                Aborting... \n' % i)
                return False

            acquisition_mode_continuous = node_acquisition_mode_continuous.GetValue(
            )

            node_acquisition_mode.SetIntValue(acquisition_mode_continuous)

            print('Camera %d acquisition mode set to continuous...' % i)

            # Begin acquiring images
            cam.BeginAcquisition()

            print('Camera %d started acquiring images...' % i)

            print()

        # Retrieve, convert, and save images for each camera
        #
        # *** NOTES ***
        # In order to work with simultaneous camera streams, nested loops are
        # needed. It is important that the inner loop be the one iterating
        # through the cameras; otherwise, all images will be grabbed from a
        # single camera before grabbing any images from another.
        for n in range(NUM_IMAGES):
            for i, cam in enumerate(cam_list):
                try:
                    # Retrieve device serial number for filename
                    node_device_serial_number = PySpin.CStringPtr(
                        cam.GetTLDeviceNodeMap().GetNode('DeviceSerialNumber'))

                    if PySpin.IsAvailable(
                            node_device_serial_number) and PySpin.IsReadable(
                                node_device_serial_number):
                        device_serial_number = node_device_serial_number.GetValue(
                        )
                        print('Camera %d serial number set to %s...' %
                              (i, device_serial_number))

                    # Retrieve next received image and ensure image completion
                    image_result = cam.GetNextImage()

                    if image_result.IsIncomplete():
                        print('Image incomplete with image status %d ... \n' %
                              image_result.GetImageStatus())
                    else:
                        # Print image information
                        width = image_result.GetWidth()
                        height = image_result.GetHeight()
                        print(
                            'Camera %d grabbed image %d, width = %d, height = %d'
                            % (i, n, width, height))

                        # Convert image to mono 8
                        image_converted = image_result.Convert(
                            PySpin.PixelFormat_Mono8, PySpin.HQ_LINEAR)

                        # Create a unique filename
                        if device_serial_number:
                            filename = 'AcquisitionMultipleCamera-%s-%d.jpg' % (
                                device_serial_number, n)
                        else:
                            filename = 'AcquisitionMultipleCamera-%d-%d.jpg' % (
                                i, n)

                        # Save image
                        image_converted.Save(filename)
                        print('Image saved at %s' % filename)

                    # Release image
                    image_result.Release()
                    print()

                except PySpin.SpinnakerException as ex:
                    print('Error: %s' % ex)
                    result = False

        # End acquisition for each camera
        #
        # *** NOTES ***
        # Notice that what is usually a one-step process is now two steps
        # because of the additional step of selecting the camera. It is worth
        # repeating that camera selection needs to be done once per loop.
        #
        # It is possible to interact with cameras through the camera list with
        # GetByIndex(); this is an alternative to retrieving cameras as
        # CameraPtr objects that can be quick and easy for small tasks.
        for cam in cam_list:

            # End acquisition
            cam.EndAcquisition()

    except PySpin.SpinnakerException as ex:
        print('Error: %s' % ex)
        result = False

    return result