相机应用代码开发基础

PG电子


PG电子

相机应用代码开发基础

API 如何使用

获取第一个 Orbbec 设备

ob::Context ctx;
auto devList = ctx.queryDeviceList();
auto dev = devList->getDevice(0);

通过默认配置开启数据流

ob::Pipeline pipe;  // create pipe with default device
pipe.start(nullptr);  // start with defualt configuratio

开启红外数据流

对于 TOF 或单目结构体光设备:

ob::Pipeline pipe;
std::shared_ptr<ob::Config> config = std::make_shared<ob::Config>();
auto irProfiles = pipe.getStreamProfileList(OB_SENSOR_IR);
auto irProfile = irProfiles->getProfile(OB_PROFILE_DEFAULT);
config->enableStream(irProfile);
pipe.start(config);

 

对于双目结构光设备:

ob::Pipeline pipe;
std::shared_ptr<ob::Config> config = std::make_shared<ob::Config>();

auto irLeftProfiles = pipe.getStreamProfileList(OB_SENSOR_IR_LEFT);
auto irLeftProfile = irLeftProfiles->getProfile(OB_PROFILE_DEFAULT);
config->enableStream(irLeftProfile);

auto irRightProfiles = pipe.getStreamProfileList(OB_SENSOR_IR_RIGHT);
auto irRightProfile = irRightProfiles->getProfile(OB_PROFILE_DEFAULT);
config->enableStream(irRightProfile);

pipe.start(config);

等待获取一组数据帧

ob::Pipeline pipe;
pipe.start(nullptr);
auto frameSet = pipe.waitForFrames(100);
auto depthFrame = frameSet->depthFrame();

在后台子线程处理数据

std::mutex frameQueueMtx;
std::queue<std::shared_ptr<ob::Frame>> frameQueue;
auto precessThread = std::thread([&](){
    std::shared_ptr<ob::Frame> depthFrame;
    while(true{
      {
        std::lock_guard<std::mutex> lk(frameQueueMtx);
        if(frameQueue.empty()){
          std::this_thread::sleep_for(std::chrono::milliseconds(10));
          continue;
        }
        depthFrame = frameQueue.front();
        frameQueue.pop();
      }
      auto depthFrameData = depthFrame->data();
      // do some thing to process depth frame data;
    }
})


ob::Pipeline pipe;
pipe.start(nullptr);
while(true){
  auto frameSet = pipe.waitForFrames(100);
  auto depthFrame = frameSet->depthFrame();

  if(depthFrame){
    std::lock_guard<std::mutex> lk(frameQueueMtx);
    frameQueue.push(depthFrame)
  }
}

获取深度到 RGB 的外参


ob::Pipeline pipe;
auto depthProfiles = pipe.getStreamProfileList(OB_SENSOR_DEPTH);
auto depthProfile = depthProfiles->getProfile(OB_PROFILE_DEFAULT);
auto colorProfiles = pipe.getStreamProfileList(OB_SENSOR_DEPTH);
auto colorProfile = depthProfiles->getProfile(OB_PROFILE_DEFAULT);

auto extrinsics = depthProfile->getExtrinsicTo(colorProfile);

获取视频流内参

通过 Pipeline 获取:

ob::Pipeline pipe;
pipe.start(nullptr);
// get camera intrinsic and extrinsic parameters form pipeline and set to point cloud filter
auto cameraParam = pipeline.getCameraParam();

 

通过 Frame/StreamProfile 获取(仅支持 Gemini 300 series):

ob::Pipeline pipe;
pipe.start(nullptr);

auto frameSet = pipe.waitForFrames(100);
auto frame = frameSet->depthFrame();
auto streamProfile = frame->getStreamProfile();
auto videoStreamProfile = streamProfile->as<ob::VideoStreamProfile>();

auto intrinsic = videoStreamProfile->getIntrinsic();

获取深度单位

ob::Pipeline pipe;
pipe.start(nullptr);

auto frameSet = pipe.waitForFrames(100);
auto depthFrame = frameSet->depthFrame();

auto uint = depthFrame->getValueScale();

控制激光

ob::Pipeline pipe;
auto dev = pipe->getDevice();

// Laser control (for Gemini 300 series)
dev->setIntProperty(OB_PROP_LASER_CONTROL_INT, 1); // 0: off, 1: on, 2: auto

// Turn on/off laser (for other series)
dev->setBoolProperty(OB_PROP_LASER_BOOL, true);

// Laser energy level control
dev->setIntProperty(OB_PROP_LASER_ENERGY_LEVEL_INT, 2);

 


友情链接: