#!/usr/bin/env python """ Copyright 2017, Zixin Luo, HKUST. IO tools. """ from __future__ import print_function import os import re import cv2 import numpy as np from struct import unpack def get_pose(R, t): T = np.zeros((4, 4), dtype=R.dtype) T[:3,:3] = R T[:3,3:] = t T[ 3, 3] = 1 return T def load_pfm(pfm_path): with open(pfm_path, 'rb') as fin: color = None width = None height = None scale = None data_type = None header = str(fin.readline().decode('UTF-8')).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$', fin.readline().decode('UTF-8')) if dim_match: width, height = map(int, dim_match.groups()) else: raise Exception('Malformed PFM header.') scale = float((fin.readline().decode('UTF-8')).rstrip()) if scale < 0: # little-endian data_type = '