Multiple Streams

<< Click to Display Table of Contents >>

Navigation:  Migration Guide for the Acquisition Stacks > CVBpy >

Multiple Streams

This example expands the use case of the single data stream example to multi stream devices, for example devices that potentially deliver more than just one data stream with potentially different data types per stream and potentially asynchronously delivered data. An example for such a device is a multispectral camera providing multiple streams transferring different spectral information.

 

Code Example

3rd generation stack

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

devices = DeviceFactory.discover_from_root(DiscoverFlags.IgnoreVins)

with DeviceFactory.open(devices[0].access_token, AcquisitionStack.GenTL) as device:

  streams = [device.stream(ImageStream, i) for i in range(device.stream_count)]

  for stream in streams:

      stream.engine_start()

  for stream in streams:

      stream.device_start()

  for _ in range(10):

      images = [stream.wait() for stream in streams]

      try:

          pass

      finally:

          for image, status, nodes in images:

              with image:

                  pass

  for stream in streams:

      stream.device_abort()

  for stream in streams:

      stream.engine_abort()

(3) Where previously only one data stream was accessed, now all available streams on the device are accessed. Therefore, the index based stream fetching is used. The number of available streams gets queried with the stream count function on the device - the queried streams are collected as image stream type. This enables parallel streaming over all streams.

(5) The acquisition engine on all streams is started.

(7) The device acquisition is started in all streams.

(17) The device acquisition has to be either stopped or aborted. Following the reverse order compared to starting the stream, now the stream control is stopped before the acquisition engines for each stream.

(19) Finally the acquisition engine is stopped / aborted on all streams.

 

Summary

When using multi stream devices, the sequence of actions necessary on a single stream device simply needs to be extended from 1 stream to N streams. This means that start, stop and wait for on the stream need to be called in a loop over all the required streams. When working with asynchronous streams it should be considered to put the Wait() calls into dedicated threads to make sure that the streams don't stall each other.