BIWI深度、彩色、位姿调用示例

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>

// 加载深度图像
int16_t* loadDepthImageCompressed(const char* fname) {

    // now read the depth image
    FILE* pFile = fopen(fname, "rb");
    if (!pFile) {
        std::cerr << "could not open file " << fname << std::endl;
        return NULL;
    }

    int im_width = 0;
    int im_height = 0;
    bool success = true;

    success &= (fread(&im_width, sizeof(int), 1, pFile) == 1); // read width of depthmap
    success &= (fread(&im_height, sizeof(int), 1, pFile) == 1); // read height of depthmap

    int16_t* depth_img = new int16_t[im_width * im_height];

    int numempty;
    int numfull;
    int p = 0;

    while (p < im_width * im_height) {

        success &= (fread(&numempty, sizeof(int), 1, pFile) == 1);

        for (int i = 0; i < numempty; i++)
            depth_img[p + i] = 0;

        success &= (fread(&numfull, sizeof(int), 1, pFile) == 1);
        success &= (fread(&depth_img[p + numempty], sizeof(int16_t), numfull, pFile) == (unsigned int)numfull);
        p += numempty + numfull;

    }

    fclose(pFile);

    if (success)
        return depth_img;
    else {
        delete[] depth_img;
        return NULL;
    }
}
float* read_gt(const char* fname) {

    // try to read in the ground truth from a binary file
    FILE* pFile = fopen(fname, "rb");
    if (!pFile) {
        std::cerr << "could not open file " << fname << std::endl;
        return NULL;
    }

    float* data = new float[6];

    bool success = true;
    success &= (fread(&data[0], sizeof(float), 6, pFile) == 6);
    fclose(pFile);

    if (success)
        return data;
    else {
        delete[] data;
        return NULL;
    }
}

// 加载RGB图像
void loadRGBImage(const std::string& directory, int frame_number) {
    std::string filename = directory + "\\frame_" + std::to_string(frame_number) + "_rgb.png";
    // 你的加载RGB图像的代码
    std::cout << "Loaded RGB image: " << filename << std::endl;
}

// 加载姿态文件
void loadPose(const std::string& directory, int frame_number) {
    std::string filename = directory + "\\frame_" + std::to_string(frame_number) + "_pose.txt";
    // 你的加载姿态文件的代码
    std::cout << "Loaded pose file: " << filename << std::endl;
}

int main() {
    const std::string directory = "C:\\Demos\\kinect_head_pose_db\\hpdb\\01";
    const int frame_number = 3;

    // 加载深度图像
    const char* depth_filename = "frame_00003_depth.bin";
    // 拼接深度图像的完整路径
    std::string depth_filepath = directory + "\\" + depth_filename;
    // 加载深度图像
    int16_t* depth_img = loadDepthImageCompressed(depth_filepath.c_str());
    if (depth_img != nullptr) {
        std::cout << "Depth image loaded successfully." << std::endl;
        // 在这里添加你的代码,对深度图像进行处理
        // 例如,释放深度图像内存:delete[] depth_img;
    }
    else {
        std::cerr << "Failed to load depth image." << std::endl;
    }

    // 加载RGB图像
    loadRGBImage(directory, frame_number);

    // 加载姿态文件
    loadPose(directory, frame_number);

    return 0;
}

在这里插入图片描述

  • 7
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值