#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;
}
在这里插入图片描述