1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > python如何读取数据集_如何读取Middlebury数据集提供的.pfm文件?

python如何读取数据集_如何读取Middlebury数据集提供的.pfm文件?

时间:2019-08-22 02:39:09

相关推荐

python如何读取数据集_如何读取Middlebury数据集提供的.pfm文件?

我试着用下面的代码根据描述读取文件: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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。