Exemplo n.º 1
0
    def get_dataset_poses(self):
        if os.path.exists(self.dataset_poses_path):
            poses = np.load(self.dataset_poses_path)
            return poses[:, :3], poses[:, 3:]

        eulers = []
        translations = []
        train_set = np.loadtxt(
            os.path.join(cfg.LINEMOD,
                         '{}/training_range.txt'.format(self.class_type)),
            np.int32)
        for idx in train_set:
            rot_path = os.path.join(self.dir_path, 'rot{}.rot'.format(idx))
            tra_path = os.path.join(self.dir_path, 'tra{}.tra'.format(idx))
            pose = read_pose(rot_path, tra_path)
            euler = self.pose_transformer.orig_pose_to_blender_euler(pose)
            eulers.append(euler)
            translations.append(pose[:, 3])

        eulers = np.array(eulers)
        translations = np.array(translations) * 5
        np.save(self.dataset_poses_path,
                np.concatenate([eulers, translations], axis=-1))

        return eulers, translations
Exemplo n.º 2
0
    def get_all_dataset_poses(self):
        eulers = []
        translations = []
        for idx in range(1188):
            rot_path = os.path.join(self.dir_path, 'rot{}.rot'.format(idx))
            tra_path = os.path.join(self.dir_path, 'tra{}.tra'.format(idx))
            pose = read_pose(rot_path, tra_path)
            # euler = self.pose_transformer.orig_pose_to_blender_euler(pose)
            pose = self.pose_transformer.orig_pose_to_blender_pose(pose)
            euler = self.pose_transformer.blender_pose_to_blender_euler(pose)

            eulers.append(euler)
            translations.append(pose[:, 3])

        eulers = np.array(eulers)
        translations = np.array(translations)
        np.save(self.dataset_poses_path,
                np.concatenate([eulers, translations], axis=-1))

        return eulers, translations
Exemplo n.º 3
0
import cv2

def fuse(img, mask, background):
    background = cv2.resize(background,(img.shape[1], img.shape[0]))
    silhouette = mask > 0
    background[silhouette] = img[silhouette]
    return background
    


class_type = 'cat'
dir_path = os.path.join(cfg.LINEMOD_ORIG,'{}/data'.format(class_type))
train_set = np.loadtxt(os.path.join(cfg.LINEMOD, '{}/training_range.txt'.format(class_type)),np.int32)

trans = PoseTransformer(class_type)

for idx in train_set:
        rot_path = os.path.join(dir_path, 'rot{}.rot'.format(idx))
        tra_path = os.path.join(dir_path, 'tra{}.tra'.format(idx))
        pose = read_pose(rot_path, tra_path)
        pose = trans.orig_pose_to_blender_pose(pose)
        rot, tra = pose[:, :3], pose[:, 3]
        break
r = OpenGLRenderer()
rgb, mask = r.render(class_type, pose, intrinsic_matrix=r.intrinsic_matrix['linemod'], render_type='all')
rgb = rgb[:,:,[2,1,0]]  # opencv use bgr order instead of rgb
background = cv2.imread('Lena.png', 1)

rgb = fuse(rgb, mask, background)
cv2.imwrite('RGB2.jpg', rgb)