数据集在这里:http://vision.middlebury.edu/stereo/data/scenes2014/
PFM文件说明如下:http://davis.lbl.gov/Manuals/NETPBM/doc/pfm.html
我试着用下面的代码根据描述读取文件:
header = file.readline().rstrip()
if header == 'PF':
color = True
elif header == 'Pf':
color = False
else:
raise Exception('Not a PFM file.')
dim_match = re.match(r'^(\d+)\s(\d+)\s$', file.readline())
if dim_match:
width, height = map(int, dim_match.groups())
else:
raise Exception('Malformed PFM header.')
scale = float(file.readline().rstrip())
if scale < 0: # little-endian
endian = '<'
scale = -scale
else:
endian = '>' # big-endian
data = np.fromfile(file, endian + 'f')
shape = (height, width, 3) if color else (height, width)
return np.reshape(data, (shape[0]-1, shape[1])), scale
但是在我的数组中得到了非常奇怪的值。但我从来没试过要得到正确的结果。因此,如果有人能帮助理解如何正确地读取这些文件,那就太好了。在
我在python2.7.11中使用Windows
相关问题 更多 >
编程相关推荐