RealSenseシリーズの記事-2.ベース接続

6603 ワード

RealSenseシリーズの記事-ベース接続
このシリーズでは、D 415/D 435について、初期の製品はWindowsプラットフォームの下で開発されたものに限定されません.
1.プロジェクト構成
VS 2015を使用して空のコンソールプロジェクトを作成し、次のコードを記述します.
#include "windows.h"
#include "stdlib.h"
#include "stdio.h"
#include 
#include "librealsense2/rs.hpp"

#pragma comment(lib, "realsense2.lib")

void main() {
    rs2::context ctx;
    auto dev_list = ctx.query_devices(); // snapshot of connected devices
    //   ,         
    int nNums = dev_list.size();
    printf("Dev num:%d
"
, nNums); if (nNums<1) { system("pause"); return; } for (auto dev : dev_list) { printf("======================================
"
); printf("Device Name: %s
"
, dev.get_info(RS2_CAMERA_INFO_NAME)); printf("Serial Num: %s
"
, dev.get_info(RS2_CAMERA_INFO_SERIAL_NUMBER)); printf("Product ID: %s
"
, dev.get_info(RS2_CAMERA_INFO_PRODUCT_ID)); printf("Physcal Port: %s
"
, dev.get_info(RS2_CAMERA_INFO_PHYSICAL_PORT)); //printf("FireWall Ver: %s
", dev.get_info(RS2_CAMERA_INFO_FIRMWARE_VERSION));
} system("pause"); }
  • は、Intel RealSense SDK 2.0\includeをincludeディレクトリに追加する.
  • は、Intel RealSense SDK 2.0\lib\x86をlibディレクトリに追加する.
  • は、Intel RealSense SDK 2.0\bin\x86\realsense2.dllをexeが存在するディレクトリにコピーします.

  • コンパイル、実行、OK!
    2.データ取得
    データを取得するには、以下のようにpipelineを使用して深度データDemoを取得する必要があります.
    #include "windows.h"
    #include "stdlib.h"
    #include "stdio.h"
    #include 
    #include "librealsense2/rs.hpp"
    
    #pragma comment(lib, "realsense2.lib")
    
    void main() {
        rs2::config cfg;
        //    2   、  、  、  、   、      。
        cfg.enable_stream(RS2_STREAM_DEPTH, -1); // -1      
        rs2::pipeline p; //          pipeline
        try
        {
            p.start(cfg); //        ,         
        }
        catch (std::exception& e)
        {
            //        ,    
            printf("Error: %s
    "
    , e.what()); system("pause"); return; } while (true) { rs2::frameset frames = p.wait_for_frames(); // rs2::depth_frame depth = frames.get_depth_frame(); // // float width = depth.get_width(); float height = depth.get_height(); // float dist_to_center = depth.get_distance(width / 2, height / 2); std::cout << width << " x " << height << " , Image Center Point Distance: " << dist_to_center << "\r"; } system("pause"); }

    困ったことに、開いているものが多くなったら、CPUは100%..
    制御レーザーセンサー:
    rs2::pipeline pipe; 
    rs2::pipeline_profile selection = pipe.start();
    rs2::device selected_device = selection.get_device();
    auto depth_sensor = selected_device.first<:depth_sensor>();
    auto scale =  depth_sensor.get_depth_scale();
    
    if (depth_sensor.supports(RS2_OPTION_EMITTER_ENABLED))
    {
        depth_sensor.set_option(RS2_OPTION_EMITTER_ENABLED, 1.f); // Enable emitter
        depth_sensor.set_option(RS2_OPTION_EMITTER_ENABLED, 0.f); // Disable emitter
    }
    if (depth_sensor.supports(RS2_OPTION_LASER_POWER))
    {
        // Query min and max values:
        auto range = depth_sensor.get_option_range(RS2_OPTION_LASER_POWER);
        depth_sensor.set_option(RS2_OPTION_LASER_POWER, range.max); // Set max power
        depth_sensor.set_option(RS2_OPTION_LASER_POWER, 0.f); // Disable laser
    }

    3.他の?
    I feel so sad!
    look: https://github.com/IntelRealSense/librealsense/issues/1050