if im_ids:
                im_ids_curr = set(im_ids_curr).intersection(im_ids)

            active_ratio = 0.6
            for im_id in im_ids_curr:

                start_time = time.time()

                print('#' * 20)
                print('scene: {}, im: {}'.format(scene_id, im_id))

                K = scene_info[im_id]['cam_K']
                # Load the images
                rgb = inout.load_im(dp['test_rgb_mpath'].format(scene_id, im_id))
                depth = inout.load_depth(dp['test_depth_mpath'].format(scene_id, im_id))
                depth *= dp['cam']['depth_scale']
                depth = depth.astype(np.uint16)  # [mm]
                im_size = (depth.shape[1], depth.shape[0])

                match_ids = list()

                for radius in dep_anchors:
                    match_ids.append('{:02d}_template_{}'.format(obj_id_in_scene, radius))

                # srcs, score for one part, active ratio, may be too low for simple objects so too many candidates?
                matches = detector.match([rgb, depth], 70, active_ratio,
                                         match_ids, dep_anchors, dep_range, masks=[])

                depth_edge = poseRefine.get_depth_edge(depth)  # already dilute & distant transform
                depth_edge = (depth_edge < 1.01).astype(np.uint8)*255  # dilute once more
Пример #2
0
        misc.ensure_dir(
            os.path.dirname(vis_mpath.format(dataset, delta, data_id, 0, 0)))

    # Load scene info and gts
    info = inout.load_info(dp[info_mpath_key].format(data_id))
    gts = inout.load_gt(dp[gt_mpath_key].format(data_id))

    im_ids = sorted(gts.keys())
    gt_stats = {}
    for im_id in im_ids:
        print('dataset: {}, scene/obj: {}, im: {}'.format(
            dataset, data_id, im_id))

        K = info[im_id]['cam_K']
        depth_path = dp[depth_mpath_key].format(data_id, im_id)
        depth_im = inout.load_depth(depth_path)
        depth_im *= dp['cam']['depth_scale']  # to [mm]
        im_size = (depth_im.shape[1], depth_im.shape[0])

        gt_stats[im_id] = []
        for gt_id, gt in enumerate(gts[im_id]):
            depth_gt = renderer.render(models[gt['obj_id']],
                                       im_size,
                                       K,
                                       gt['cam_R_m2c'],
                                       gt['cam_t_m2c'],
                                       mode='depth')

            # Get distance images
            dist_gt = misc.depth_im_to_dist_im(depth_gt, K)
            dist_im = misc.depth_im_to_dist_im(depth_im, K)
Пример #3
0
    info = inout.load_info(dp[info_mpath_key].format(data_id))
    gts = inout.load_gt(dp[gt_mpath_key].format(data_id))

    # Considered subset of images for the current scene
    if im_ids_sets is not None:
        im_ids = im_ids_sets[data_id]
    else:
        im_ids = sorted(gts.keys())

    gt_stats = {}
    for im_id in im_ids:
        print('dataset: {}, scene/obj: {}, im: {}'.format(dataset, data_id, im_id))

        K = info[im_id]['cam_K']
        depth_path = dp[depth_mpath_key].format(data_id, im_id)
        depth_im = inout.load_depth(depth_path)
        depth_im *= dp['cam']['depth_scale'] # to [mm]
        im_size = (depth_im.shape[1], depth_im.shape[0])

        gt_stats[im_id] = []
        for gt_id, gt in enumerate(gts[im_id]):
            depth_gt = renderer.render(models[gt['obj_id']], im_size, K,
                                       gt['cam_R_m2c'], gt['cam_t_m2c'],
                                       mode='depth')

            # Get distance images
            dist_gt = misc.depth_im_to_dist_im(depth_gt, K)
            dist_im = misc.depth_im_to_dist_im(depth_im, K)

            # Estimation of visibility mask
            visib_gt = visibility.estimate_visib_mask_gt(dist_im, dist_gt, delta)
    obj_id = scene_id  # The object id is the same as scene id for this dataset
    model = inout.load_ply(model_mpath.format(obj_id))

    # Transformation which was applied to the object models (its inverse will
    # be applied to the GT poses):
    # 1) Translate the bounding box center to the origin
    t_model = bbox_cens[obj_id - 1, :].reshape((3, 1))

    im_id_out = 0
    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.load_im(rgb_in_mpath.format(scene_id, im_id))
        depth = inout.load_depth(depth_in_mpath.format(scene_id, im_id))

        depth *= 10.0  # Convert depth map to [100um]

        # Save the RGB and depth image
        inout.save_im(rgb_out_mpath.format(scene_id, im_id_out), rgb)
        inout.save_depth(depth_out_mpath.format(scene_id, im_id_out), depth)

        scene_info[im_id_out] = {'cam_K': par['cam']['K'].flatten().tolist()}

        # Process the GT poses
        poses = load_tejani_poses(pose_mpath.format(scene_id, im_id))
        scene_gt[im_id_out] = []
        for pose in poses:
            R_m2c = pose['R']
            t_m2c = pose['t']
Пример #5
0
    if im_ids_sets is not None:
        im_ids_curr = im_ids_sets[scene_id]
    else:
        im_ids_curr = sorted(scene_info.keys())

    if im_ids:
        im_ids_curr = set(im_ids_curr).intersection(im_ids)

    for im_id in im_ids_curr:
        print('scene: {}, im: {}'.format(scene_id, im_id))

        K = scene_info[im_id]['cam_K']
        render_K = K
        # Load the images
        rgb = inout.load_im(dp['test_rgb_mpath'].format(scene_id, im_id))
        depth = inout.load_depth(dp['test_depth_mpath'].format(scene_id, im_id))
        depth = depth.astype(np.uint16)  # [mm]
        # depth *= dp['cam']['depth_scale']  # to [mm]
        im_size = (depth.shape[1], depth.shape[0])

        match_ids = list()
        match_ids.append('{:02d}_template'.format(scene_id))
        start_time = time.time()

        # result = cxx_3d_seg.convex_cloud_seg(rgb, depth, K.astype(np.float32))
        result = cxx_3d_seg_pybind.convex_cloud_seg(rgb, depth, K.astype(np.float32))
        indices = result.getIndices()
        cloud = result.getCloud()
        normal = result.getNormal()

        # just test one seg result, may break because it's not guaranteed as an object mask