-->
# 多路流同时开流示例-MultiStream
功能描述:本示例主要演示用device同时打开多个sensor流的操作,显示多路流图像,并通过ESC_KEY键退出程序
> 本示例基于C++ high Level API进行演示
首先需要创建一个pipeline
ob::Pipeline pipe
枚举设备,并进行流配置
// enumerate and config all sensors
auto device = pipe.getDevice();
auto sensorList = device->getSensorList();
for(int i = 0; i < sensorList->count(); i++) {
auto sensorType = sensorList->type(i);
if(sensorType == OB_SENSOR_GYRO || sensorType == OB_SENSOR_ACCEL) {
continue;
}
auto profiles = pipe.getStreamProfileList(sensorType);
auto profile = profiles->getProfile(OB_PROFILE_DEFAULT);
config->enableStream(profile);
}
通过配置开启pipeline
// Start the pipeline with config
std::mutex frameMutex;
std::map<OBFrameType, std::shared_ptr<ob::Frame>> frameMap;
pipe.start(config, [&](std::shared_ptr<ob::FrameSet> frameset) {
auto count = frameset->frameCount();
for(int i = 0; i < count; i++) {
auto frame = frameset->getFrame(i);
std::unique_lock<std::mutex> lk(frameMutex);
frameMap[frame->type()] = frame;
}
});
The IMU frame rate is much faster than the video, so it is advisable to use a separate pipeline to obtain IMU data.
auto dev = pipe.getDevice();
auto imuPipeline = std::make_shared<ob::Pipeline>(dev);
std::mutex imuFrameMutex;
std::map<OBFrameType, std::shared_ptr<ob::Frame>> imuFrameMap;
try {
auto accelProfiles = imuPipeline->getStreamProfileList(OB_SENSOR_ACCEL);
auto gyroProfiles = imuPipeline->getStreamProfileList(OB_SENSOR_GYRO);
auto accelProfile = accelProfiles->getProfile(OB_PROFILE_DEFAULT);
auto gyroProfile = gyroProfiles->getProfile(OB_PROFILE_DEFAULT);
std::shared_ptr<ob::Config> imuConfig = std::make_shared<ob::Config>();
imuConfig->enableStream(accelProfile);
imuConfig->enableStream(gyroProfile);
imuPipeline->start(imuConfig, [&](std::shared_ptr<ob::FrameSet> frameset) {
auto count = frameset->frameCount();
for(int i = 0; i < count; i++) {
auto frame = frameset->getFrame(i);
std::unique_lock<std::mutex> lk(imuFrameMutex);
imuFrameMap[frame->type()] = frame;
}
});
}
catch(...) {
std::cout << "IMU sensor not found!" << std::endl;
imuPipeline.reset();
}
关闭pipeline
pipe.stop()
关闭IMU pipeline
imuPipeline->stop();
预期输出: