Ejemplo n.º 1
0
 def j2d_processing(self, kp, center, scale, r, f, is_train):
     """Process gt 2D keypoints and apply all augmentation transforms."""
     nparts = kp.shape[0]
     for i in range(nparts):
         kp[i,0:2] = transform(kp[i,0:2]+1, center, scale, 
                               [constants.IMG_RES, constants.IMG_RES], rot=r)
     # convert to normalized coordinates
     kp[:,:-1] = 2.*kp[:,:-1]/constants.IMG_RES - 1.
     # flip the x coordinates
     if is_train and f:
          kp = flip_kp(kp)
     kp = kp.astype('float32')
     return kp
Ejemplo n.º 2
0
 def j2d_processing(self, kp, center, scale, r, f):
     """Process gt 2D keypoints and apply all augmentation transforms."""
     nparts = kp.shape[0]
     for i in range(nparts):
         kp[i,0:2] = transform(kp[i,0:2]+1, center, scale, 
                               [self.options.img_res, self.options.img_res], rot=r)
     # convert to normalized coordinates
     kp[:,:-1] = 2.*kp[:,:-1]/self.options.img_res - 1.
     # flip the x coordinates
     if f:
          kp = flip_kp(kp)
     kp = kp.astype('float32')
     return kp
Ejemplo n.º 3
0
    def j2d_heatmap_processing(self, kp, center, scale, r, f):
        # first process the keypoints
        nparts = kp.shape[0]
        for i in range(nparts):
            kp[i, 0:2] = transform(kp[i, 0:2] + 1, center, scale,
                                   [constants.IMG_RES, constants.IMG_RES], rot=r)
        # flip the x coordinates
        if f:
            kp = flip_kp(kp)

        # generate guaissan heatmap
        target_weight = np.ones((self.num_joints, 1), dtype=np.float32)
        target_weight[:, 0] = kp[:, -1]
        target = np.zeros((self.num_joints, self.heatmap_size[1], self.heatmap_size[0]), dtype=np.float32)
        tmp_size = self.sigma * 3

        for joint_id in range(self.num_joints):
            feat_stride = self.options.img_res / self.heatmap_size
            mu_x = int(kp[joint_id][0] / feat_stride[0] + 0.5)
            mu_y = int(kp[joint_id][1] / feat_stride[1] + 0.5)
            # Check that any part of the gaussian is in-bounds
            ul = [int(mu_x - tmp_size), int(mu_y - tmp_size)]
            br = [int(mu_x + tmp_size + 1), int(mu_y + tmp_size + 1)]
            if ul[0] >= self.heatmap_size[0] or ul[1] >= self.heatmap_size[1] \
                    or br[0] < 0 or br[1] < 0:
                # If not, just return the image as is
                target_weight[joint_id] = 0
                continue

            # # Generate gaussian
            size = 2 * tmp_size + 1
            x = np.arange(0, size, 1, np.float32)
            y = x[:, np.newaxis]
            x0 = y0 = size // 2
            # The gaussian is not normalized, we want the center value to equal 1
            g = np.exp(- ((x - x0) ** 2 + (y - y0) ** 2) / (2 * self.sigma ** 2))

            # Usable gaussian range
            g_x = max(0, -ul[0]), min(br[0], self.heatmap_size[0]) - ul[0]
            g_y = max(0, -ul[1]), min(br[1], self.heatmap_size[1]) - ul[1]
            # Image range
            img_x = max(0, ul[0]), min(br[0], self.heatmap_size[0])
            img_y = max(0, ul[1]), min(br[1], self.heatmap_size[1])

            v = target_weight[joint_id]
            if v > 0.5:
                target[joint_id][img_y[0]:img_y[1], img_x[0]:img_x[1]] = \
                    g[g_y[0]:g_y[1], g_x[0]:g_x[1]]

        return target, target_weight
Ejemplo n.º 4
0
 def j3d_processing(self, S, r, f):
     """Process gt 3D keypoints and apply all augmentation transforms."""
     # in-plane rotation
     rot_mat = np.eye(3)
     if not r == 0:
         rot_rad = -r * np.pi / 180
         sn, cs = np.sin(rot_rad), np.cos(rot_rad)
         rot_mat[0, :2] = [cs, -sn]
         rot_mat[1, :2] = [sn, cs]
     S = np.einsum('ij,kj->ki', rot_mat, S)
     # flip the x coordinates
     if f:
         S = flip_kp(S)
     S = S.astype('float32')
     return S
Ejemplo n.º 5
0
    def j2d_heatmap_location_processing(self, kp, center, scale, r, f):
        # first process the keypoints
        nparts = kp.shape[0]
        for i in range(nparts):
            kp[i, 0:2] = transform(kp[i, 0:2] + 1, center, scale,
                                   [constants.IMG_RES, constants.IMG_RES], rot=r)
        # flip the x coordinates
        if f:
            kp = flip_kp(kp)

        kp_heatmaps = kp.copy().astype(np.uint8)
        feat_stride = constants.IMG_RES / self.heatmap_size
        kp_heatmaps[:, :-1] = kp_heatmaps[:, :-1] / feat_stride
        kp_heatmaps = kp_heatmaps.astype('float32')
        return kp_heatmaps