opencv读取raw文件的深度图,并提取深度信息
int width = 1536;
int height = 1280;
const int CHANNELS = 1; // 1个通道,因为是单通道深度图
cv::Mat depthImage(height, width, CV_16SC1);
// 打开raw文件
std::ifstream file("./image/Depth/20240730195736_W[1536]_H[1280].raw", std::ios::binary);
if (!file) {
std::cerr << "无法打开文件: " << "./image/Depth.raw" << std::endl;
return;
}
std::cout << "sizeof(int16_t): " << sizeof(int16_t) << std::endl;
// 读取数据到Mat对象
file.read(reinterpret_cast<char*>(depthImage.data), width * height * sizeof(int16_t));
file.close();
if (depthImage.empty())
{
return;
}
// 打印图像的基本信息
std::cout << "Image size: " << depthImage.size() << std::endl;
std::cout << "Image type: " << depthImage.type() << std::endl;
int16_t depth = depthImage.at<int16_t>(753, 793);
std::cout << "Depth at (" << 753 << ", " << 793 << "): " << depth << " mm" << std::endl;