diff --git a/data/create_syn_data.py b/data/create_syn_data.py index 6ffb104..a8b119f 100644 --- a/data/create_syn_data.py +++ b/data/create_syn_data.py @@ -90,7 +90,7 @@ def get_mesh(rng, min_z=0): return verts, faces, colors, normals -def create_data(out_root, idx, n_samples, imsize, patterns, K, baseline, blend_im, noise, track_length=4): +def create_data(out_root, idx, n_samples, imsize, patterns, K_cam, K_proj, baseline, blend_im, noise, track_length=4): tic = time.time() rng = np.random.RandomState() @@ -139,17 +139,21 @@ def create_data(out_root, idx, n_samples, imsize, patterns, K, baseline, blend_i # render the scene at multiple scales scales = [1, 0.5, 0.25, 0.125] for scale in scales: - fx = K[0, 0] * scale - fy = K[1, 1] * scale - px = K[0, 2] * scale - py = K[1, 2] * scale + fx_cam = K_cam[0, 0] * scale + fy_cam = K_cam[1, 1] * scale + px_cam = K_cam[0, 2] * scale + py_cam = K_cam[1, 2] * scale + fx_proj = K_proj[0, 0] * scale + fy_proj = K_proj[1, 1] * scale + px_proj = K_proj[0, 2] * scale + py_proj = K_proj[1, 2] * scale im_height = imsize[0] * scale // 1 im_width = imsize[1] * scale // 1 - cams.append(renderer.PyCamera(fx, fy, px, py, Rcam, tcam, im_width, im_height)) - projs.append(renderer.PyCamera(fx, fy, px, py, Rproj, tproj, im_width, im_height)) + cams.append(renderer.PyCamera(fx_cam, fy_cam, px_cam, py_cam, Rcam, tcam, im_width, im_height)) + projs.append(renderer.PyCamera(fx_proj, fy_proj, px_proj, py_proj, Rproj, tproj, im_width, im_height)) for s, cam, proj, pattern in zip(itertools.count(), cams, projs, patterns): - fl = K[0, 0] / (2 ** s) + fl = K_cam[0, 0] / (2 ** s) shader = renderer.PyShader(0.5, 1.5, 0.0, 10) pyrenderer = renderer.PyRenderer(cam, shader, engine='gpu') @@ -208,8 +212,9 @@ def load_camera_parameters(): # 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 + K_cam = np.array(cam_mat['opencv_storage']['cam_int']['data'].split(), dtype=float).reshape(K_shape).T + K_proj = np.array(cam_mat['opencv_storage']['proj_int']['data'].split(), dtype=float).reshape(K_shape).T + return imsize, K_cam, K_proj if __name__ == '__main__': @@ -242,7 +247,7 @@ if __name__ == '__main__': objs = get_objs(shapenet_root, obj_classes) # camera parameters - imsize, K = load_camera_parameters() + imsize, K_cam, K_proj = load_camera_parameters() # remember what was set in the settings imsize = settings_imsize @@ -278,5 +283,5 @@ if __name__ == '__main__': # start the job n_samples = 2 ** 10 + 2 ** 13 for idx in range(start, n_samples): - args = (out_root, idx, n_samples, imsize, patterns, K, baseline, blend_im, noise, track_length) + args = (out_root, idx, n_samples, imsize, patterns, K_cam, K_proj, baseline, blend_im, noise, track_length) create_data(*args)