Common Vision Blox 15.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Friends Modules Pages
Acquisition and Streaming - Multiple Streams

Some devices may be able to provide multiple independent data streams with potentially different data types. An example for such a device is a multispectral device providing multiple streams transferring different spectral information or a device streaming a depth image and a RGB color image at the same time.

The only modification required to support multi-stream devices is to create and start all streams, then check on each stream for more data in a loop.

using namespace Cvb;
auto devices = Cvb::DeviceFactory::Discover(DiscoverFlags::IgnoreVins);
auto device = DeviceFactory::Open<GenICamDevice>(devices[0].AccessToken(), AcquisitionStack::GenTL);
std::vector<ImageStreamPtr> streams;
for (int i = 0; i < device->StreamCount(); ++i) {
streams.push_back(device->Stream<ImageStream>(i)) // (1)
}
for (int i = 0; i < streams.size(); ++i) {
streams[i]->Start(); // (2)
}
int streamIndex = 0;
while(true)
{
std::chrono::milliseconds TIMEOUT(3000);
WaitStatus status;
std::tie(image, status, nodeMaps) = streams[streamIndex]->WaitFor(TIMEOUT); // (3)
streamIndex = (streamIndex + 1) % streams.size();
if (status == WaitStatus::Timeout) {
// No data on this stream, try the next stream
continue;
}
//Process image
}
for (int i = 0; i < streams.size(); ++i) {
streams[i]->Abort(); // (4)
}
static std::vector< DiscoveryInformation > Discover()
static std::shared_ptr< T > Open(const String &provider, AcquisitionStack acquisitionStack=AcquisitionStack::PreferVin)
WaitStatus
std::shared_ptr< Image > ImagePtr

using (var devices = DeviceFactory.Discover(DiscoverFlags.IgnoreVins))
{
using (var device = (GenICamDevice)DeviceFactory.Open(devices[0], AcquisitionStack.GenTL))
{
var streams = new List<ImageStream>;
for (int i = 0; i < device.StreamCount(); ++i) {
streams.Add(device->GetStream<ImageStream>(i)) // (1)
}
foreach (ImageStream stream in streams) {
stream.Start(); // (2)
}
int streamIndex = 0;
while(true) {
UsTimeSpan TIMEOUT(3000);
WaitStatus status;
using (var image = streams[streamIndex].WaitFor(TIMEOUT, out status)) // (3)
{
streamIndex = (streamIndex + 1) % streams.size();
if (status = WaitStatus.Timeout) {
continue;
}
//Process image
}
}
foreach (ImageStream stream in streams) {
stream.Abort(); // (4)
}
}
}
static Device Open(DiscoveryInformation info, AcquisitionStack acquisitionStack=AcquisitionStack.PreferVin)
static DiscoveryInformationList Discover()

import cvb
devices = cvb.DeviceFactory.discover_from_root(cvb.DiscoverFlags.IgnoreVins)
with cvb.DeviceFactory.open(devices[0].access_token, cvb.AcquisitionStack.GenTL) as device:
streams = []
for i in range(0, device.StreamCount()):
streams.append(device.stream(cvb.ImageStream, i)) # (1)
for stream in streams:
stream.start() # (2)
streamIndex = 0
while True:
TIMEOUT = 3000
image, status, node_maps = streams[streamIndex].wait(TIMEOUT) # (3)
streamIndex = (streamIndex + 1) % streams.size()
if status == WaitStatus.Timeout:
continue
# Process image
for stream in streams:
stream.abort() # (4)
Union[cvb.GenICamDevice, cvb.VinDevice, cvb.EmuDevice, cvb.VideoDevice, cvb.NonStreamingDevice] open(str provider, int acquisition_stack=cvb.AcquisitionStack.PreferVin)
List[cvb.DiscoveryInformation] discover_from_root(int flags=cvb.DiscoverFlags.FindAll, int time_span=300)

Note: Error handling has been omitted from the above example.

Note: Waiting for data is sequential for simplicity; using concurrent waits (e.g. using async or thread) is more likely.

  1. All data streams are instantiated. Note: The order does not matter.
  2. Acquisition is started for all data streams. Note: The order does not matter.
  3. Each composite will need to be proactively waited for by means of a call to wait on the stream. In this case, to prevent blocking indefinitely if one stream does not have data, the Cvb::Stream::WaitFor with timeout is used. If the status is Cvb::WaitStatus::Timeout, no data was received and the next stream can checked.
  4. All streams are aborted. Note: The order does not matter.