【发布时间】:2015-02-17 20:29:07
【问题描述】:
要读取一帧的深度数据,必须跳过深度文件的前 28 个字节,其余是 320*240 无符号短的数组,即 320*240*2 字节(因为每个深度帧有 320 x 240 像素)。我已经包含了用于读取深度文件的代码,但是当我尝试运行它时它总是挂起。请告诉我如何更正代码。
int main()
{
int array_size = 76800*2;
char *data[array_size];
unsigned short depth[320][240];
int i,j;
// open the depth file in read mode.
ifstream infile("000000.depth");
// check for error in opening file
if(!infile.is_open())
{
std::cout<< "File could not be opened";
return 1;
}
std::cout << "Reading from the file" << endl;
infile.seekg(29,ios::beg); // discarding first 28 bytes
while(!infile.eof())
{
infile >> data[array_size];
}
// storing data in required array
for (i=0; i = 320; i++)
{
for (j=0; j=240; j++)
{
depth[i][j] = (unsigned short)atof(data[i*j]);
std::cout << depth[i][j] << endl;
}
}
infile.close();
getch();
return(0);
}
【问题讨论】:
-
用
while(eof)读取是错误的,没有以二进制模式打开文件,for循环使用赋值而不是比较,你为char*分配空间而不是为char分配空间。跨度> -
如果您提供
000000.depth文件内容的示例(前60个字节,只是为了查看格式),我会很好
标签: c++ file computer-vision kinect