• <rt id="2awkm"><noscript id="2awkm"></noscript></rt>
      <rt id="2awkm"><noscript id="2awkm"></noscript></rt>
    • <dfn id="2awkm"></dfn>
      <menu id="2awkm"><acronym id="2awkm"></acronym></menu>
      
      
      <rt id="2awkm"></rt><dfn id="2awkm"><code id="2awkm"></code></dfn>
    • <dd id="2awkm"><s id="2awkm"></s></dd>
      <tbody id="2awkm"></tbody>
    • <dfn id="2awkm"></dfn>
      <menu id="2awkm"><noscript id="2awkm"></noscript></menu>

      創(chuàng)建您的第一個相機預(yù)覽應(yīng)用

      本快速入門指南將引導(dǎo)您通過使用Orbbec SDK 獲取相機多路流。該文檔參考了C++示例MultiStream。

       

       

      先決條件

      連接Orbbec設(shè)備。
      下載并安裝Orbbec SDK。

       

       

      頭文件

      包含Orbbec SDK的主要頭文件:

      #include "window.hpp"

      #include "libobsensor/hpp/Pipeline.hpp"
      #include "libobsensor/hpp/Error.hpp"
      #include <mutex>
      #include <thread>

       

      初始化Pipeline

       

          // Create a pipeline with default device
          ob::Pipeline pipe;

          // Configure which streams to enable or disable for the Pipeline by creating a Config
          std::shared_ptr<ob::Config> config = std::make_shared<ob::Config>();

       

       

      配置流

       

      根據(jù)設(shè)備上可用的sensor配置要啟用哪些流。

       

          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);
          }

       

       

      Start Pipeline

      啟動配置了視頻流的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;
              }
          });

       

      獲取IMU 數(shù)據(jù)

      由于 IMU 傳感器幀率高,單獨處理IMU數(shù)據(jù)。

         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();
          }

       

      渲染幀

      創(chuàng)建一個用于渲染收集到的幀的窗口:

          Window app("MultiStream", 1280, 720, RENDER_GRID);
          while(app) {
              std::vector<std::shared_ptr<ob::Frame>> framesForRender;
              {
                  std::unique_lock<std::mutex> lock(frameMutex);
                  for(auto &frame: frameMap) {
                      framesForRender.push_back(frame.second);
                  }
              }
              {
                  std::unique_lock<std::mutex> lock(imuFrameMutex);
                  for(auto &frame: imuFrameMap) {
                      framesForRender.push_back(frame.second);
                  }
              }
              app.addToRender(framesForRender);
          }

       

       

      停止Pipeline

      在應(yīng)用程序關(guān)閉時正確停止Pipeline,以確保釋放所有資源。

          pipe.stop();
          if(imuPipeline) {
              imuPipeline->stop();
          }

       

       

      完整代碼

      這是一個完整應(yīng)用程序的代碼

      #include "window.hpp"

      #include "libobsensor/hpp/Pipeline.hpp"
      #include "libobsensor/hpp/Error.hpp"
      #include <mutex>
      #include <thread>

      int main(int argc, char **argv) try {
          // Create a pipeline with default device
          ob::Pipeline pipe;

          // Configure which streams to enable or disable for the Pipeline by creating a Config
          std::shared_ptr<ob::Config> config = std::make_shared<ob::Config>();

          // 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);
          }

          // 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();
          }

          // Create a window for rendering and set the resolution of the window
          Window app("MultiStream", 1280, 720, RENDER_GRID);
          while(app) {
              std::vector<std::shared_ptr<ob::Frame>> framesForRender;
              {
                  std::unique_lock<std::mutex> lock(frameMutex);
                  for(auto &frame: frameMap) {
                      framesForRender.push_back(frame.second);
                  }
              }
              {
                  std::unique_lock<std::mutex> lock(imuFrameMutex);
                  for(auto &frame: imuFrameMap) {
                      framesForRender.push_back(frame.second);
                  }
              }
              app.addToRender(framesForRender);
          }

          // Stop the Pipeline, no frame data will be generated
          pipe.stop();
          if(imuPipeline) {
              imuPipeline->stop();
          }
          return 0;
      }
      catch(ob::Error &e) {
          std::cerr << "function:" << e.getName() << "\nargs:" << e.getArgs() << "\nmessage:" << e.getMessage() << "\ntype:" << e.getExceptionType() << std::endl;
          exit(EXIT_FAILURE);
      }

       

       

      下一步

       

      -了解如何使用Orbbec SDK配置和使用單個傳感器。

      -探索 Orbbec SDK 文檔中提供的高級功能和設(shè)置。

      -開始將 Orbbec 設(shè)備功能集成到您的大型項目和應(yīng)用程序中。

       

       


      • <rt id="2awkm"><noscript id="2awkm"></noscript></rt>
        <rt id="2awkm"><noscript id="2awkm"></noscript></rt>
      • <dfn id="2awkm"></dfn>
        <menu id="2awkm"><acronym id="2awkm"></acronym></menu>
        
        
        <rt id="2awkm"></rt><dfn id="2awkm"><code id="2awkm"></code></dfn>
      • <dd id="2awkm"><s id="2awkm"></s></dd>
        <tbody id="2awkm"></tbody>
      • <dfn id="2awkm"></dfn>
        <menu id="2awkm"><noscript id="2awkm"></noscript></menu>
        亚洲国产精品18久久久久久 | 久一久一做一爱一视频 | 色狠狠一区二区三区香蕉 | 婷婷99狠狠躁天天躁中文字幕 | 欧美 级黑寡妇毛片app |