【发布时间】:2015-03-09 15:48:03
【问题描述】:
我有一个 .binary 文件,其中包含来自 kinect 传感器的深度数据。
我正在尝试浏览 .binary 文件并在 MATLAB 中取回实际图像。所以这是我想出的 MATLAB 程序:
fid = fopen('E:\KinectData\March7Pics\Depth\Depth_Raw_0.binary');
col = 512; %// Change if the dimensions are not proper
row = 424;
frames = {}; %// Empty cell array - Put frames in here
numFrames = 0; %// Let's record the number of frames too
while (true) %// Until we reach the end of the file:
B = fread(fid, [col row],'ushort=>ushort'); %// Read in one frame at a time
if (isempty(B)) %// If there are no more frames, get out
break;
end
frames{end+1} = B.'; %// Transpose to make row major and place in cell array
numFrames = numFrames + 1; %// Count frame
imwrite(frames{numFrames},sprintf('Depth_%03d.png',numFrames));
end
%// Close the file
fclose(fid);
frm = frames{1};
imagesc(frm)
colormap(gray)
上面的程序运行良好,但它不会给我任何高于 99 的图像。 也就是说,我将处理 .binary 文件,而我获得的最后一张图像是 Depth_099.png,即使完整视频的内容不止于此。
有人认识你吗? 谢谢
【问题讨论】:
-
如果您需要更多数字,为什么不直接使用 %04d 呢? %03d 将文件名限制为 3 位数字并填充 0。
-
这段代码是否包含在更大的
while循环中,循环遍历帧号?如果可以,您能否发布整个代码? -
是的,我已经尝试过了,但不幸的是,提高精度不起作用。不,它不在 while 循环内。
标签: matlab image-processing computer-vision kinect