def print_device_info(nodemap): """ 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. :type nodemap: INodeMap :returns: True if successful, False otherwise. :rtype: bool """ print('*** DEVICE INFORMATION ***\n') 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.') except PySpin.SpinnakerException as ex: print('Error: %s' % ex) return False return result
def print_boolean_node(node, level): """ Retrieves and prints the display name and value of a Boolean node. :param node: Node to get information from. :type node: INode :param level: Depth to indent output. :type level: int :return: True if successful, False otherwise. :rtype: bool """ try: result = True # Create Boolean node node_boolean = PySpin.CBooleanPtr(node) # Get display name display_name = node_boolean.GetDisplayName() # Retrieve Boolean value value = node_boolean.GetValue() # Print Boolean value # NOTE: In Python a Boolean will be printed as "True" or "False". print_with_indent(level, "%s: %s" % (display_name, value)) except PySpin.SpinnakerException as ex: print "Error: %s" % ex return False return result
def print_float_node(node, level): """ Retrieves and prints the display name and value of a float node. :param node: Node to get information from. :type node: INode :param level: Depth to indent output. :type level: int :return: True if successful, False otherwise. :rtype: bool """ try: result = True # Create float node node_float = PySpin.CFloatPtr(node) # Get display name display_name = node_float.GetDisplayName() # Retrieve float value value = node_float.GetValue() # Print value print_with_indent(level, "%s: %s" % (display_name, value)) except PySpin.SpinnakerException as ex: print "Error: %s" % ex return False return result
def print_integer_node(node, level): """ Retrieves and prints the display name and value of an integer node. :param node: Node to get information from. :type node: INode :param level: Depth to indent output. :type level: int :return: True if successful, False otherwise. :rtype: bool """ try: result = True # Create integer node node_integer = PySpin.CIntegerPtr(node) # Get display name display_name = node_integer.GetDisplayName() # Retrieve integer node value # # *** NOTES *** # All node types except base nodes have a ToString() # method which returns a value as a string. value = node_integer.GetValue() # Print value print_with_indent(level, "%s: %s" % (display_name, value)) except PySpin.SpinnakerException as ex: print "Error: %s" % ex return False return result
def print_enumeration_node_and_current_entry(node, level): """ This function retrieves and prints the display names of an enumeration node and its current entry (which is actually housed in another node unto itself). :param node: Node to get information from. :type node: INode :param level: Depth to indent output. :type level: int :return: True if successful, False otherwise. :rtype: bool """ try: result = True # Create enumeration node node_enumeration = PySpin.CEnumerationPtr(node) # Retrieve current entry as enumeration node # # *** NOTES *** # Enumeration nodes have three methods to differentiate between: first, # GetIntValue() returns the integer value of the current entry node; # second, GetCurrentEntry() returns the entry node itself; and third, # ToString() returns the symbolic of the current entry. node_enum_entry = PySpin.CEnumEntryPtr( node_enumeration.GetCurrentEntry()) # Get display name display_name = node_enumeration.GetDisplayName() # Retrieve current symbolic # # *** NOTES *** # Rather than retrieving the current entry node and then retrieving its # symbolic, this could have been taken care of in one step by using the # enumeration node's ToString() method. entry_symbolic = node_enum_entry.GetSymbolic() # Print current entry symbolic print_with_indent(level, "%s: %s" % (display_name, entry_symbolic)) except PySpin.SpinnakerException as ex: print "Error: %s" % ex return False return result
def acquire_and_display_images(cam, number): result = True nodemap_tldevice = cam.GetTLDeviceNodeMap() cam.Init() nodemap = cam.GetNodeMap() node_acquisition_mode = PySpin.CEnumerationPtr(nodemap.GetNode('AcquisitionMode')) node_acquisition_mode_continuous = node_acquisition_mode.GetEntryByName('Continuous') acquisition_mode_continuous = node_acquisition_mode_continuous.GetValue() node_acquisition_mode.SetIntValue(acquisition_mode_continuous) cam.BeginAcquisition() node_device_serial_number = PySpin.CStringPtr(nodemap_tldevice.GetNode('DeviceSerialNumber')) image_result = cam.GetNextImage(1000) image_data = image_result.GetNDArray() cv2.imshow(str(number),image_data) cv2.waitKey(1) image_result.Release() cam.EndAcquisition() return True
def print_value_node(node, level): """ Retrieves and prints the display name and value of all node types as value nodes. A value node is a general node type that allows for the reading and writing of any node type as a string. :param node: Node to get information from. :type node: INode :param level: Depth to indent output. :type level: int :return: True if successful, False otherwise. :rtype: bool """ try: result = True # Create value node node_value = PySpin.CValuePtr(node) # Retrieve display name # # *** NOTES *** # A node's 'display name' is generally more appropriate for output and # user interaction whereas its 'name' is what the camera understands. # Generally, its name is the same as its display name but without # spaces - for instance, the name of the node that houses a camera's # serial number is 'DeviceSerialNumber' while its display name is # 'Device Serial Number'. display_name = node_value.GetDisplayName() # Retrieve value of any node type as string # # *** NOTES *** # Because value nodes return any node type as a string, it can be much # easier to deal with nodes as value nodes rather than their actual # individual types. value = node_value.ToString() # Cap length at MAX_CHARS value = value[:MAX_CHARS] + '...' if len(value) > MAX_CHARS else value # Print value print_with_indent(level, "%s: %s" % (display_name, value)) except PySpin.SpinnakerException as ex: print "Error: %s" % ex return False return result
def print_command_node(node, level): """ This function retrieves and prints the display name and tooltip of a command node, limiting the number of printed characters to a macro-defined maximum. The tooltip is printed below because command nodes do not have an intelligible value. :param node: Node to get information from. :type node: INode :param level: Depth to indent output. :type level: int :return: True if successful, False otherwise. :rtype: bool """ try: result = True # Create command node node_command = PySpin.CCommandPtr(node) # Get display name display_name = node_command.GetDisplayName() # Retrieve tooltip # # *** NOTES *** # All node types have a tooltip available. Tooltips provide useful # information about nodes. Command nodes do not have a method to # retrieve values as their is no intelligible value to retrieve. tooltip = node_command.GetToolTip() # Ensure that the value length is not excessive for printing tooltip = tooltip[:MAX_CHARS] + '...' if len( tooltip) > MAX_CHARS else tooltip # Print display name and tooltip print_with_indent(level, "%s: %s" % (display_name, tooltip)) except PySpin.SpinnakerException as ex: print "Error: %s" % ex return False return result
def print_string_node(node, level): """ Retrieves and prints the display name and value of a string node. :param node: Node to get information from. :type node: INode :param level: Depth to indent output. :type level: int :return: True if successful, False otherwise. :rtype: bool """ try: result = True # Create string node node_string = PySpin.CStringPtr(node) # Retrieve string node value # # *** NOTES *** # Functions in Spinnaker C++ that use gcstring types # are substituted with Python strings in PySpin. # The only exception is shown in the DeviceEvents example, where # the callback function still uses a wrapped gcstring type. display_name = node_string.GetDisplayName() # Ensure that the value length is not excessive for printing value = node_string.GetValue() value = value[:MAX_CHARS] + '...' if len(value) > MAX_CHARS else value # Print value; 'level' determines the indentation level of output print_with_indent(level, "%s: %s" % (display_name, value)) except PySpin.SpinnakerException as ex: print "Error: %s" % ex return False return result
def acquire_and_display_images(cam, nodemap, nodemap_tldevice): """ This function continuously acquires images from a device and display them in a GUI. :param cam: Camera to acquire images from. :param nodemap: Device nodemap. :param nodemap_tldevice: Transport layer device nodemap. :type cam: CameraPtr :type nodemap: INodeMap :type nodemap_tldevice: INodeMap :return: True if successful, False otherwise. :rtype: bool """ global continue_recording sNodemap = cam.GetTLStreamNodeMap() # Change bufferhandling mode to NewestOnly node_bufferhandling_mode = PySpin.CEnumerationPtr( sNodemap.GetNode('StreamBufferHandlingMode')) if not PySpin.IsAvailable( node_bufferhandling_mode) or not PySpin.IsWritable( node_bufferhandling_mode): print('Unable to set stream buffer handling mode.. Aborting...') return False # Retrieve entry node from enumeration node node_newestonly = node_bufferhandling_mode.GetEntryByName('NewestOnly') if not PySpin.IsAvailable(node_newestonly) or not PySpin.IsReadable( node_newestonly): print('Unable to set stream buffer handling mode.. Aborting...') return False # Retrieve integer value from entry node node_newestonly_mode = node_newestonly.GetValue() # Set integer value from entry node as new value of enumeration node node_bufferhandling_mode.SetIntValue(node_newestonly_mode) print('*** IMAGE ACQUISITION ***\n') try: node_acquisition_mode = PySpin.CEnumerationPtr( 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) print('Acquisition mode set to continuous...') # Begin acquiring images # # *** NOTES *** # What happens when the camera begins acquiring images depends on the # acquisition mode. Single frame captures only a single image, multi # frame catures a set number of images, and continuous captures a # continuous stream of images. # # *** LATER *** # Image acquisition must be ended when no more images are needed. cam.BeginAcquisition() print('Acquiring images...') # Retrieve device serial number for filename # # *** NOTES *** # The device serial number is retrieved in order to keep cameras from # overwriting one another. Grabbing image IDs could also accomplish # this. device_serial_number = '' node_device_serial_number = PySpin.CStringPtr( nodemap_tldevice.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('Device serial number retrieved as %s...' % device_serial_number) # Close program print('Press enter to close the program..') # Figure(1) is default so you can omit this line. Figure(0) will create a new window every time program hits this line fig = plt.figure(1) # Close the GUI when close event happens fig.canvas.mpl_connect('close_event', handle_close) # Retrieve and display images while (continue_recording): try: # Retrieve next received image # # *** NOTES *** # Capturing an image houses images on the camera buffer. Trying # to capture an image that does not exist will hang the camera. # # *** LATER *** # Once an image from the buffer is saved and/or no longer # needed, the image must be released in order to keep the # buffer from filling up. image_result = cam.GetNextImage(1000) # Ensure image completion if image_result.IsIncomplete(): print('Image incomplete with image status %d ...' % image_result.GetImageStatus()) else: # Getting the image data as a numpy array image_data = image_result.GetNDArray() # Draws an image on the current figure plt.imshow(image_data, cmap='gray') # Interval in plt.pause(interval) determines how fast the images are displayed in a GUI # Interval is in seconds. plt.pause(0.001) # Clear current reference of a figure. This will improve display speed significantly plt.clf() # If user presses enter, close the program if keyboard.is_pressed('ENTER'): print('Program is closing...') # Close figure plt.close('all') input('Done! Press Enter to exit...') continue_recording = False # Release image # # *** NOTES *** # Images retrieved directly from the camera (i.e. non-converted # images) need to be released in order to keep from filling the # buffer. image_result.Release() except PySpin.SpinnakerException as ex: print('Error: %s' % ex) return False # End acquisition # # *** NOTES *** # Ending acquisition appropriately helps ensure that devices clean up # properly and do not need to be power-cycled to maintain integrity. cam.EndAcquisition() except PySpin.SpinnakerException as ex: print('Error: %s' % ex) return False return True
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(1000) 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
def acquire_images(cam, nodemap, nodemap_tldevice): """ This function acquires and saves 10 images from a device. :param cam: Camera to acquire images from. :param nodemap: Device nodemap. :param nodemap_tldevice: Transport layer device nodemap. :type cam: CameraPtr :type nodemap: INodeMap :type nodemap_tldevice: INodeMap :return: True if successful, False otherwise. :rtype: bool """ print('*** IMAGE ACQUISITION ***\n') try: result = True # Set acquisition mode to continuous # # *** NOTES *** # Because the example acquires and saves 10 images, setting acquisition # mode to continuous lets the example finish. If set to single frame # or multiframe (at a lower number of images), the example would just # hang. This would happen because the example has been written to # acquire 10 images while the camera would have been programmed to # retrieve less than that. # # Setting the value of an enumeration node is slightly more complicated # than other node types. Two nodes must be retrieved: first, the # enumeration node is retrieved from the nodemap; and second, the entry # node is retrieved from the enumeration node. The integer value of the # entry node is then set as the new value of the enumeration node. # # Notice that both the enumeration and the entry nodes are checked for # availability and readability/writability. Enumeration nodes are # generally readable and writable whereas their entry nodes are only # ever readable. # # Retrieve enumeration node from nodemap # In order to access the node entries, they have to be casted to a pointer type (CEnumerationPtr here) node_acquisition_mode = PySpin.CEnumerationPtr(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) print('Acquisition mode set to continuous...') # Begin acquiring images # # *** NOTES *** # What happens when the camera begins acquiring images depends on the # acquisition mode. Single frame captures only a single image, multi # frame catures a set number of images, and continuous captures a # continuous stream of images. Because the example calls for the # retrieval of 10 images, continuous mode has been set. # # *** LATER *** # Image acquisition must be ended when no more images are needed. cam.BeginAcquisition() print('Acquiring images...') # Retrieve device serial number for filename # # *** NOTES *** # The device serial number is retrieved in order to keep cameras from # overwriting one another. Grabbing image IDs could also accomplish # this. device_serial_number = '' node_device_serial_number = PySpin.CStringPtr(nodemap_tldevice.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('Device serial number retrieved as %s...' % device_serial_number) # Retrieve, convert, and save images for i in range(NUM_IMAGES): try: # Retrieve next received image # # *** NOTES *** # Capturing an image houses images on the camera buffer. Trying # to capture an image that does not exist will hang the camera. # # *** LATER *** # Once an image from the buffer is saved and/or no longer # needed, the image must be released in order to keep the # buffer from filling up. image_result = cam.GetNextImage(1000) # Ensure image completion # # *** NOTES *** # Images can easily be checked for completion. This should be # done whenever a complete image is expected or required. # Further, check image status for a little more insight into # why an image is incomplete. if image_result.IsIncomplete(): print('Image incomplete with image status %d ...' % image_result.GetImageStatus()) else: # Print image information; height and width recorded in pixels # # *** NOTES *** # Images have quite a bit of available metadata including # things such as CRC, image status, and offset values, to # name a few. width = image_result.GetWidth() height = image_result.GetHeight() print('Grabbed Image %d, width = %d, height = %d' % (i, width, height)) # Convert image to mono 8 # # *** NOTES *** # Images can be converted between pixel formats by using # the appropriate enumeration value. Unlike the original # image, the converted one does not need to be released as # it does not affect the camera buffer. # # When converting images, color processing algorithm is an # optional parameter. image_converted = image_result.Convert(PySpin.PixelFormat_Mono8, PySpin.HQ_LINEAR) # Create a unique filename if device_serial_number: filename = 'Acquisition-%s-%d.jpg' % (device_serial_number, i) else: # if serial number is empty filename = 'Acquisition-%d.jpg' % i # Save image # # *** NOTES *** # The standard practice of the examples is to use device # serial numbers to keep images of one device from # overwriting those of another. image_converted.Save(filename) print('Image saved at %s' % filename) # Release image # # *** NOTES *** # Images retrieved directly from the camera (i.e. non-converted # images) need to be released in order to keep from filling the # buffer. image_result.Release() print('') except PySpin.SpinnakerException as ex: print('Error: %s' % ex) return False # End acquisition # # *** NOTES *** # Ending acquisition appropriately helps ensure that devices clean up # properly and do not need to be power-cycled to maintain integrity. cam.EndAcquisition() except PySpin.SpinnakerException as ex: print('Error: %s' % ex) return False return result
def query_interface(interface): """ Queries an interface for its cameras and prints out device information. :param interface: InterfacePtr :return: True if successful, False otherwise. :rtype: bool """ try: result = True # Retrieve TL nodemap from interface # # *** NOTES *** # Each interface has a nodemap that can be retrieved in order to # access information about the interface itself, any devices # connected, or addressing information if applicable. nodemap_interface = interface.GetTLNodeMap() # Print interface display name # # *** NOTES *** # Grabbing node information requires first retrieving the node and # then retrieving its information. There are two things to keep in # mind. First, a node is distinguished by type, which is related # to its value's data type. Second, nodes should be checked for # availability and readability/writability prior to making an # attempt to read from or write to the node. # # Note that for Python, the node retrieved then has to be 'cast' # to the proper type (CStringPtr in this case) before it can be used. node_interface_display_name = PySpin.CStringPtr( nodemap_interface.GetNode("InterfaceDisplayName")) if PySpin.IsAvailable( node_interface_display_name) and PySpin.IsReadable( node_interface_display_name): interface_display_name = node_interface_display_name.GetValue() print interface_display_name else: print "Interface display name not readable" # Update list of cameras on the interface # # *** NOTES *** # Updating the cameras on each interface is especially important if # there has been any device arrivals or removals since the last time # that UpdateCameras() was called. interface.UpdateCameras() # Retrieve list of cameras from the interface # # *** NOTES *** # Camera lists can be retrieved from an interface or the system object. # Camera lists retrieved from an interface, such as this one, only # return cameras attached on that specific interface whereas camera # lists retrieved from the system will return all cameras on all # interfaces. # # *** LATER *** # Camera lists must be cleared manually. This must be done prior to # releasing the system and while the camera list is still in scope. cam_list = interface.GetCameras() # Retrieve number of cameras num_cams = cam_list.GetSize() # Return if no cameras detected if num_cams == 0: print "\tNo devices detected.\n" return result # Print device vendor and model name for each camera on the interface for i in range(num_cams): # Select camera # # *** NOTES *** # Each camera is retrieved from a camera list with an index. If # the index is out of range, an exception is thrown. cam = cam_list[i] # Retrieve TL device nodemap; please see NodeMapInfo example for # additional comments on transport layer nodemaps nodemap_tldevice = cam.GetTLDeviceNodeMap() # Print device vendor name and device model name # # *** NOTES *** # Grabbing node information requires first retrieving the node and # then retrieving its information. There are two things to keep in # mind. First, a node is distinguished by type, which is related # to its value's data type. Second, nodes should be checked for # availability and readability/writability prior to making an # attempt to read from or write to the node. node_device_vendor_name = PySpin.CStringPtr( nodemap_tldevice.GetNode("DeviceVendorName")) if PySpin.IsAvailable( node_device_vendor_name) and PySpin.IsReadable( node_device_vendor_name): device_vendor_name = node_device_vendor_name.ToString() node_device_model_name = PySpin.CStringPtr( nodemap_tldevice.GetNode("DeviceModelName")) if PySpin.IsAvailable( node_device_model_name) and PySpin.IsReadable( node_device_model_name): device_model_name = node_device_model_name.ToString() print "\tDevice %i %s %s \n" % (i, device_vendor_name, device_model_name) # Clear camera list before losing scope # # *** NOTES *** # Camera lists (and interface lists) must be cleared manually while in # the same scope that the system is released. However, in cases like this # where scope is lost, camera lists (and interface lists) will be cleared # automatically. cam_list.Clear() except PySpin.SpinnakerException as ex: print "Error: %s" % ex result = False return result
def print_category_node_and_all_features(node, level): """ This function retrieves and prints out the display name of a category node before printing all child nodes. Child nodes that are also category nodes are printed recursively. :param node: Category node to get information from. :type node: INode :param level: Depth to indent output. :type level: int :return: True if successful, False otherwise. :rtype: bool """ try: result = True # Create category node node_category = PySpin.CCategoryPtr(node) # Get and print display name display_name = node_category.GetDisplayName() print_with_indent(level, display_name) # Retrieve and iterate through all children # # *** NOTES *** # The two nodes that typically have children are category nodes and # enumeration nodes. Throughout the examples, the children of category nodes # are referred to as features while the children of enumeration nodes are # referred to as entries. Keep in mind that enumeration nodes can be cast as # category nodes, but category nodes cannot be cast as enumerations. for node_feature in node_category.GetFeatures(): # Ensure node is available and readable if not PySpin.IsAvailable(node_feature) or not PySpin.IsReadable( node_feature): continue # Category nodes must be dealt with separately in order to retrieve subnodes recursively. if node_feature.GetPrincipalInterfaceType( ) == PySpin.intfICategory: result &= print_category_node_and_all_features( node_feature, level + 1) # Cast all non-category nodes as value nodes # # *** NOTES *** # If dealing with a variety of node types and their values, it may be # simpler to cast them as value nodes rather than as their individual types. # However, with this increased ease-of-use, functionality is sacrificed. elif CHOSEN_READ == ReadType.VALUE: result &= print_value_node(node_feature, level + 1) # Cast all non-category nodes as actual types elif CHOSEN_READ == ReadType.INDIVIDUAL: if node_feature.GetPrincipalInterfaceType( ) == PySpin.intfIString: result &= print_string_node(node_feature, level + 1) elif node_feature.GetPrincipalInterfaceType( ) == PySpin.intfIInteger: result &= print_integer_node(node_feature, level + 1) elif node_feature.GetPrincipalInterfaceType( ) == PySpin.intfIFloat: result &= print_float_node(node_feature, level + 1) elif node_feature.GetPrincipalInterfaceType( ) == PySpin.intfIBoolean: result &= print_boolean_node(node_feature, level + 1) elif node_feature.GetPrincipalInterfaceType( ) == PySpin.intfICommand: result &= print_command_node(node_feature, level + 1) elif node_feature.GetPrincipalInterfaceType( ) == PySpin.intfIEnumeration: result &= print_enumeration_node_and_current_entry( node_feature, level + 1) print "" except PySpin.SpinnakerException as ex: print "Error: %s" % ex return False return result