Beispiel #1
0
    def __getitem__(self, index):
        image_path = self.images[index]
        kps = self.kp2ds[index].copy()
        box = self.boxs[index]

        scale = np.random.rand(4) * (self.scale_range[1] -
                                     self.scale_range[0]) + self.scale_range[0]
        image, kps = cut_image(image_path, kps, scale, box[0], box[1])
        ratio = 1.0 * args.crop_size / image.shape[0]
        kps[:, :2] *= ratio
        dst_image = cv2.resize(image, (args.crop_size, args.crop_size),
                               interpolation=cv2.INTER_CUBIC)

        if self.use_flip and random.random() <= self.flip_prob:
            dst_image, kps = flip_image(dst_image, kps)

        #normalize kp to [-1, 1]
        ratio = 1.0 / args.crop_size
        kps[:, :2] = 2.0 * kps[:, :2] * ratio - 1.0
        return {
            'image':
            torch.tensor(
                convert_image_by_pixformat_normalize(dst_image,
                                                     self.pix_format,
                                                     self.normalize)).float(),
            'kp_2d':
            torch.tensor(kps).float(),
            'image_name':
            self.images[index],
            'data_set':
            'lsp'
        }
    def __getitem__(self, index):
        image_path = self.images[index]
        kps = self.kp2ds[index].copy()
        pose = self.poses[index].copy()
        shape = self.betas[index].copy()

        dst_image = cv2.imread(image_path)

        if self.use_flip and random.random() <= self.flip_prob:
            dst_image, kps = flip_image(dst_image, kps)
            pose = reflect_poses(pose)

        #normalize kp to [-1, 1]
        ratio = 1.0 / args.crop_size
        kps[:, :2] = 2.0 * kps[:, :2] * ratio - 1.0

        return {
            'image':
            torch.tensor(
                convert_image_by_pixformat_normalize(dst_image,
                                                     self.pix_format,
                                                     self.normalize)).float(),
            'kp_2d':
            torch.tensor(kps).float(),
            'pose':
            torch.tensor(pose).float(),
            'shape':
            torch.tensor(shape).float(),
            'image_name':
            self.images[index],
            'data_set':
            'up_3d_evaluation'
        }
    def __getitem__(self, index):
        image_path = self.images[index]
        kps = self.kp2ds[index].copy()
        box = self.boxs[index]
        kp_3d = self.kp3ds[index].copy()

        scale = np.random.rand(4) * (self.scale_range[1] -
                                     self.scale_range[0]) + self.scale_range[0]
        image, kps = cut_image(image_path, kps, scale, box[0], box[1])

        ratio = 1.0 * args.crop_size / image.shape[0]
        kps[:, :2] *= ratio
        dst_image = cv2.resize(image, (args.crop_size, args.crop_size),
                               interpolation=cv2.INTER_CUBIC)

        trival, shape, pose = np.zeros(
            3), self.shapes[index], self.poses[index]

        if self.use_flip and random.random() <= self.flip_prob:
            dst_image, kps = flip_image(dst_image, kps)
            pose = reflect_pose(pose)
            kp_3d = reflect_lsp_kp(kp_3d)

        #normalize kp to [-1, 1]
        ratio = 1.0 / args.crop_size
        kps[:, :2] = 2.0 * kps[:, :2] * ratio - 1.0

        theta = np.concatenate((trival, pose, shape), axis=0)

        return {
            'image':
            torch.from_numpy(
                convert_image_by_pixformat_normalize(dst_image,
                                                     self.pix_format,
                                                     self.normalize)).float(),
            'kp_2d':
            torch.from_numpy(kps).float(),
            'kp_3d':
            torch.from_numpy(kp_3d).float(),
            'theta':
            torch.from_numpy(theta).float(),
            'image_name':
            self.images[index],
            'w_smpl':
            1.0,
            'w_3d':
            1.0,
            'data_set':
            'hum3.6m'
        }
Beispiel #4
0
    def __init__(self):
        num_views = 9

        self.albedo_png = 'output/tentacle_albedo.png'
        self.normals_png = 'output/tentacle_normals.png'
        self.normals_npy = 'output/tentacle_normals.npy'
        self.ncc_png = 'output/tentacle_ncc.png'
        self.depth_npy = 'output/tentacle_depth.npy'
        self.mesh_ply = 'output/tentacle_mesh_{0}.ply'

        self.ncc_temp = 'temp/tentacle_ncc-%03d.png'
        self.ncc_gif = 'output/tentacle_ncc.gif'
        self.projected_temp = 'temp/tentacle_projected-%03d.png'
        self.projected_gif = 'output/tentacle_projected.gif'

        self.stereo_downscale_factor = 3

        self.mesh_downscale_factor = 0

        self.ncc_size = 5

        self.depth_weight = 1

        self.min_depth = 24
        self.max_depth = 45
        self.depth_layers = 128

        self.chessboard_dims = (5, 5)

        self.right = [
            flip_image(np.float32(imread('input/right/%04d.png' % (i + 1))))
            for i in range(num_views)
        ]
        self.left = [
            flip_image(np.float32(imread('input/left/%04d.png' % (i + 1))))
            for i in range(num_views)
        ]

        self.height = 1920
        self.width = 1080

        self.left_alpha = self.left[0][:, :, 3]
        self.right_alpha = self.right[0][:, :, 3]

        for image in self.right:
            assert image.shape == (self.height, self.width, 4)
            assert (self.right_alpha == image[:, :, 3]).all()

        for image in self.left:
            assert image.shape == (self.height, self.width, 4)
            assert (self.left_alpha == image[:, :, 3]).all()

        self.left = [x[:, :, :3] for x in self.left]
        self.right = [x[:, :, :3] for x in self.right]

        rotations = (
            (0, 0),
            (0, 15),
            (0, -15),
            (-15, 15),
            (-15, 15),
            (15, 15),
            (15, -15),
            (15, 0),
            (-15, 0),
        )

        assert len(rotations) == num_views

        lights = []
        for rotx, roty in rotations:
            direction = np.array(((0.0, ), (0.0, ), (1.0, )))

            radians_x = rotx / 180.0 * pi
            new_x = direction[1] * cos(radians_x) - \
                direction[2] * sin(radians_x)
            new_y = direction[1] * sin(radians_x) + \
                direction[2] * cos(radians_x)
            direction[1] = new_x
            direction[2] = new_y

            radians_y = roty / 180.0 * pi
            new_z = direction[2] * cos(radians_y) - \
                direction[0] * sin(radians_y)
            new_x = direction[2] * sin(radians_y) + \
                direction[0] * cos(radians_y)
            direction[2] = new_z
            direction[0] = new_x

            lights.append(direction)

        self.lights = np.hstack(lights)

        self.K_left = np.array(
            ((2100, 0, self.width / 2), (0, 2100, self.height / 2), (0, 0, 1)))
        self.K_right = np.array(
            ((2100, 0, self.width / 2), (0, 2100, self.height / 2), (0, 0, 1)))

        calib = np.load('input/calibration.npz')
        self.Rt_right = calib['Rt_right']
        self.Rt_left = calib['Rt_left']