Load camera parameters from calibration xml

master
CptCaptain 3 years ago
parent 0c8529687b
commit 83d202457a
  1. 18
      data/create_syn_data.py

@ -11,6 +11,8 @@ import os
import collections import collections
import sys import sys
import xmltodict as xmltodict
sys.path.append('../') sys.path.append('../')
import renderer import renderer
import co import co
@ -201,6 +203,16 @@ def create_data(out_root, idx, n_samples, imsize, patterns, K, baseline, blend_i
print(f'create sample {idx + 1}/{n_samples} took {time.time() - tic}[s]') print(f'create sample {idx + 1}/{n_samples} took {time.time() - tic}[s]')
def load_camera_parameters():
with open('calibration_result.xml') as f:
cam_mat = xmltodict.parse(f.read())
# weird casting cause the values are str(float) (eg. '123.'), but we want int
imsize = [int(float(x)) for x in cam_mat['opencv_storage']['img_shape']['data'].split()]
K_shape = int(cam_mat['opencv_storage']['cam_int']['rows']), int(cam_mat['opencv_storage']['cam_int']['cols'])
K = np.array(cam_mat['opencv_storage']['cam_int']['data'].split(), dtype=float).reshape(K_shape).T
return imsize, K
if __name__ == '__main__': if __name__ == '__main__':
np.random.seed(42) np.random.seed(42)
@ -230,11 +242,9 @@ if __name__ == '__main__':
objs = get_objs(shapenet_root, obj_classes) objs = get_objs(shapenet_root, obj_classes)
# camera parameters # camera parameters
imsize = (488, 648) imsize, K = load_camera_parameters()
imsizes = [(imsize[0] // (2 ** s), imsize[1] // (2 ** s)) for s in range(4)] imsizes = [(imsize[0] // (2 ** s), imsize[1] // (2 ** s)) for s in range(4)]
# K = np.array([[567.6, 0, 324.7], [0, 570.2, 250.1], [0 ,0, 1]], dtype=np.float32)
K = np.array([[1929.5936336276382, 0, 113.66561071478046], [0, 1911.2517985448746, 473.70108079885887], [0, 0, 1]],
dtype=np.float32)
focal_lengths = [K[0, 0] / (2 ** s) for s in range(4)] focal_lengths = [K[0, 0] / (2 ** s) for s in range(4)]
baseline = 0.075 baseline = 0.075
blend_im = 0.6 blend_im = 0.6

Loading…
Cancel
Save