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.
std::vector<ImageStreamPtr> streams;
for (int i = 0; i < device->StreamCount(); ++i) {
}
for (int i = 0; i < streams.size(); ++i) {
streams[i]->Start();
}
int streamIndex = 0;
while(true)
{
std::chrono::milliseconds TIMEOUT(3000);
std::tie(image, status, nodeMaps) = streams[streamIndex]->WaitFor(TIMEOUT);
streamIndex = (streamIndex + 1) % streams.size();
if (status == WaitStatus::Timeout) {
continue;
}
}
for (int i = 0; i < streams.size(); ++i) {
streams[i]->Abort();
}
static std::vector< DiscoveryInformation > Discover()
static std::shared_ptr< T > Open(const String &provider, AcquisitionStack acquisitionStack=AcquisitionStack::PreferVin)
std::shared_ptr< Image > ImagePtr
{
{
var streams = new List<ImageStream>;
for (int i = 0; i < device.StreamCount(); ++i) {
}
}
int streamIndex = 0;
while(true) {
UsTimeSpan TIMEOUT(3000);
using (var
image = streams[streamIndex].WaitFor(TIMEOUT, out status))
{
streamIndex = (streamIndex + 1) % streams.size();
continue;
}
}
}
}
}
}
static Device Open(DiscoveryInformation info, AcquisitionStack acquisitionStack=AcquisitionStack.PreferVin)
static DiscoveryInformationList Discover()
import cvb
streams = []
for i in range(0, device.StreamCount()):
for stream in streams:
stream.start()
streamIndex = 0
while True:
TIMEOUT = 3000
image, status, node_maps = streams[streamIndex].wait(TIMEOUT)
streamIndex = (streamIndex + 1) % streams.size()
if status == WaitStatus.Timeout:
continue
for stream in streams:
stream.abort()
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.
- All data streams are instantiated. Note: The order does not matter.
- Acquisition is started for all data streams. Note: The order does not matter.
- 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.
- All streams are aborted. Note: The order does not matter.