RGB-D相机(Azure Kinect DK)RGB图、深度图的获取,配准与保存

RGB-D相机(Azure Kinect DK)RGB图、深度图的获取,配准与保存

        前提:官方apt安装Azure Kinect 传感器 SDK

        代码AcquiringImages将原始深度图转换到RGB摄像头坐标系下,得到的配准后的深度图,并将转换后的depth图,原始RGB图、原始IR图保存在本地,采集格式仿照TUM数据集,图片的命名格式为时间戳+.png后缀。

1.C++代码:

// C++
#include <iostream>
#include <chrono>
#include <string>
// OpenCV
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
// Kinect DK
#include <k4a/k4a.hpp>

using namespace cv;
using namespace std;

// 宏
// 方便控制是否 std::cout 信息
#define DEBUG_std_cout 0

int main(int argc, char *argv[]) {
   
    /*
        找到并打开 Azure Kinect 设备
    */
    // 发现已连接的设备数
    
const uint32_t device_count = k4a::device::get_installed_count();
    if (0 == device_count) {
   
        std::cout << "Error: no K4A devices found. " << std::endl;
        return -1;
    } else {
   
    std::cout << "Found " << device_count << " connected devices. " << std::endl;
     if (1 != device_count)// 超过1个设备,也输出错误信息。
        {
   
            std::cout << "Error: more than one K4A devices found. " << std::endl;
            return -1;
             } else// 该示例代码仅限对1个设备操作
        {
   
            std::cout << "Done: found 1 K4A device. " << std::endl;
        }
    }
    // 打开(默认)设备
    k4a::device device = k4a::device::open(K4A_DEVICE_DEFAULT);
    std::cout << "Done: open device. " << std::endl;

    /*
        检索并保存 Azure Kinect 图像数据
    */
    // 配置并启动设备
    k4a_device_configuration_t config = K4A_DEVICE_CONFIG_INIT_DISABLE_ALL;
    config.camera_fps = K4A_FRAMES_PER_SECOND_30;
    config.color_format = K4A_IMAGE_FORMAT_COLOR_BGRA32;
    config.color_resolution = K4A_COLOR_RESOLUTION_1080P;
    config.depth_mode = K4A_DEPTH_MODE_NFOV_UNBINNED;
    //config.depth_mode = K4A_DEPTH_MODE_WFOV_2X2BINNED;
    config.synchronized_images_only = true;// ensures that depth and color images are both available in the capture
     device.start_cameras(&config);
    std::cout << "Done: start camera." << std::endl;

    //写入txt文件流
    ofstream rgb_out;
    ofstream d_out;
    ofstream ir_out;
    
    rgb_out.open("./rgb.txt");
    d_out.open("./depth.txt");
    ir_out.open("./ir.txt");
    
    rgb_out<<"#  color images"<<endl;
    rgb_out<<"#  file: rgbd_dataset"<<endl;
    rgb_out<<"#  timestamp"<<"    "<<"filename"<<endl;
    
    d_out<<"#  depth images"<<endl;
    d_out<<"#  file: rgbd_dataset"<<endl;
    d_out<<"#  timestamp"<<"    "<<"filename"<<endl;

    ir_out<<"# 
评论 29
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值