K_rgb, view['R'], view['t'], clip_near, clip_far, texture=model_texture, ambient_weight=ambient_weight, shading=shading, mode='rgb') rgb = cv2.resize(rgb, par['cam']['im_size'], interpolation=cv2.INTER_AREA) # Save the rendered images inout.write_im(out_rgb_mpath.format(obj_id, im_id), rgb) inout.write_depth(out_depth_mpath.format(obj_id, im_id), depth) # Get 2D bounding box of the object model at the ground truth pose ys, xs = np.nonzero(depth > 0) obj_bb = misc.calc_2d_bbox(xs, ys, par['cam']['im_size']) obj_info[im_id] = { 'cam_K': par['cam']['K'].flatten().tolist(), 'view_level': int(views_level[view_id]), #'sphere_radius': float(radius) } obj_gt[im_id] = [{ 'cam_R_m2c': view['R'].flatten().tolist(), 'cam_t_m2c': view['t'].flatten().tolist(), 'obj_bb': [int(x) for x in obj_bb],
import os import sys import glob import numpy as np sys.path.append(os.path.abspath('..')) from pysixd import inout from params.dataset_params import get_dataset_params par = get_dataset_params('hinterstoisser') # data_ids = range(1, par.obj_count + 1) data_ids = range(1, par['scene_count'] + 1) # depth_mpath = par.train_depth_mpath depth_mpath = par['test_depth_mpath'] scale = 0.1 for data_id in data_ids: print('Processing id: ' + str(data_id)) depth_paths = sorted( glob.glob( os.path.join(os.path.dirname(depth_mpath.format(data_id, 0)), '*'))) for depth_path in depth_paths: d = inout.read_depth(depth_path) d *= scale d = np.round(d).astype(np.uint16) inout.write_depth(depth_path, d)
R_model_inv = np.linalg.inv(R_model) for im_id in im_ids: if im_id % 10 == 0: print('scene,view: ' + str(scene_id) + ',' + str(im_id)) # Load the RGB and depth image rgb = inout.read_im(rgb_in_mpath.format(scene_id, im_id)) depth = load_hinter_depth(depth_in_mpath.format(scene_id, im_id)) depth *= 10.0 # Convert depth map to [100um] # Save the RGB and depth image inout.write_im(rgb_out_mpath.format(scene_id, im_id), rgb) inout.write_depth(depth_out_mpath.format(scene_id, im_id), depth) # Load the GT pose R_m2c = load_hinter_mat(rot_mpath.format(scene_id, im_id)) t_m2c = load_hinter_mat(tra_mpath.format(scene_id, im_id)) t_m2c *= 10 # Convert to [mm] # Transfom the GT pose (to compensate transformation of the models) R_m2c = R_m2c.dot(R_model_inv) t_m2c = t_m2c + R_m2c.dot(R_model.dot(t_model)) # Get 2D bounding box of the object model at the ground truth pose obj_bb = misc.calc_pose_2d_bbox(model, par['cam']['im_size'], par['cam']['K'], R_m2c, t_m2c) # Visualisation