Skip to content

Instantly share code, notes, and snippets.

@josephbima
Created April 3, 2021 04:23
Show Gist options
  • Save josephbima/67b6bb82baa1587a9608dd9a8213fecc to your computer and use it in GitHub Desktop.
Save josephbima/67b6bb82baa1587a9608dd9a8213fecc to your computer and use it in GitHub Desktop.
NUM_IMAGES = 4000 # The number of images to capture
NUM_SAVERS = 10 # The number of saver coroutines
BUFFER_SIZE = 3500
# Set up cam_list and queue
system = PySpin.System.GetInstance()
cam_list = system.GetCameras()
queue = asyncio.Queue()
for cam in cam_list:
# Retrieve Stream Parameters device nodemap
s_node_map = cam.GetTLStreamNodeMap()
# Retrieve Buffer Handling Mode Information
handling_mode = PySpin.CEnumerationPtr(s_node_map.GetNode('StreamBufferHandlingMode'))
if not PySpin.IsAvailable(handling_mode) or not PySpin.IsWritable(handling_mode):
print('Unable to set Buffer Handling mode (node retrieval). Aborting...\n')
#return False
handling_mode_entry = PySpin.CEnumEntryPtr(handling_mode.GetCurrentEntry())
if not PySpin.IsAvailable(handling_mode_entry) or not PySpin.IsReadable(handling_mode_entry):
print('Unable to set Buffer Handling mode (Entry retrieval). Aborting...\n')
#return False
# Set stream buffer Count Mode to manual
stream_buffer_count_mode = PySpin.CEnumerationPtr(s_node_map.GetNode('StreamBufferCountMode'))
if not PySpin.IsAvailable(stream_buffer_count_mode) or not PySpin.IsWritable(stream_buffer_count_mode):
print('Unable to set Buffer Count Mode (node retrieval). Aborting...\n')
# return False
stream_buffer_count_mode_manual = PySpin.CEnumEntryPtr(stream_buffer_count_mode.GetEntryByName('Manual'))
if not PySpin.IsAvailable(stream_buffer_count_mode_manual) or not PySpin.IsReadable(stream_buffer_count_mode_manual):
print('Unable to set Buffer Count Mode entry (Entry retrieval). Aborting...\n')
#return False
stream_buffer_count_mode.SetIntValue(stream_buffer_count_mode_manual.GetValue())
print('Stream Buffer Count Mode set to manual...')
# Retrieve and modify Stream Buffer Count
buffer_count = PySpin.CIntegerPtr(s_node_map.GetNode('StreamBufferCountManual'))
if not PySpin.IsAvailable(buffer_count) or not PySpin.IsWritable(buffer_count):
print('Unable to set Buffer Count (Integer node retrieval). Aborting...\n')
# return False
# Display Buffer Info
print('\nDefault Buffer Handling Mode: %s' % handling_mode_entry.GetDisplayName())
print('Default Buffer Count: %d' % buffer_count.GetValue())
print('Maximum Buffer Count: %d' % buffer_count.GetMax())
handling_mode_entry = handling_mode.GetEntryByName('OldestFirstOverwrite')
handling_mode.SetIntValue(handling_mode_entry.GetValue())
buffer_count.SetValue(BUFFER_SIZE)
print('Buffer count now set to: %d' % buffer_count.GetValue())
print('Now Buffer Handling Mode: %s' % handling_mode_entry.GetDisplayName())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment