Beispiel #1
0
    def process_image(self, sample_index, kpanno, sigma, rot_flag, scale_flag,
                      flip_flag):
        imagefile = kpanno['img_paths']
        # -image = scipy.misc.imread(os.path.join(self.imgpath, imagefile))
        image = imageio.imread(os.path.join(self.imgpath, imagefile))

        # get center
        center = np.array(kpanno['objpos'])
        joints = np.array(kpanno['joint_self'])
        scale = kpanno['scale_provided']

        # Adjust center/scale slightly to avoid cropping limbs
        if center[0] != -1:
            center[1] = center[1] + 15 * scale
            scale = scale * 1.25

        # filp
        if flip_flag and random.choice([0, 1]):
            image, joints, center = self.flip(image, joints, center)

        # scale
        if scale_flag:
            scale = scale * np.random.uniform(0.8, 1.2)

        # rotate image
        if rot_flag and random.choice([0, 1]):
            rot = np.random.randint(-1 * 30, 30)
        else:
            rot = 0

        cropimg = data_process.crop(image, center, scale, self.inres, rot)
        cropimg = data_process.normalize(cropimg, self.get_color_mean())

        # transform keypoints
        transformedKps = data_process.transform_kp(joints, center, scale,
                                                   self.outres, rot)
        gtmap = data_process.generate_gtmap(transformedKps, sigma, self.outres)

        # meta info
        metainfo = {
            'sample_index': sample_index,
            'center': center,
            'scale': scale,
            'pts': joints,
            'tpts': transformedKps,
            'name': imagefile
        }

        return cropimg, gtmap, metainfo
Beispiel #2
0
    def process_image(self, sample_index, kpanno, sigma):
        imagefile = 'rgb_1_' + str(sample_index + 1).zfill(7) + '.jpg'
        image = imageio.imread(os.path.join(self.imgpath, imagefile))

        # norm_image = data_process.normalize(image, self.get_color_mean(image)) #UNNECESSARY
        norm_image = image / 255.0

        # create heatmaps
        heatmaps, orig_size_map = data_process.generate_gtmap(
            kpanno, sigma, self.outres)

        if self.debug:
            orig_image = cv2.resize(
                image, dsize=(480, 480), interpolation=cv2.INTER_CUBIC) / 255.0
            im = np.concatenate(
                [orig_image,
                 np.sum(orig_size_map, axis=-1)[:, :, np.newaxis]],
                axis=-1)

            for i in range(kpanno.shape[0]):
                x = kpanno[i, 0]
                y = kpanno[i, 1]
                orig_image = cv2.circle(orig_image, (int(x), int(y)), 5,
                                        (0, 0, 255), 2)

            cv2.imshow('orig {} with heatmaps GENERATOR'.format(sample_index),
                       orig_image)
            cv2.imshow('orig {} heatmap GENERATOR'.format(sample_index),
                       np.sum(orig_size_map, axis=-1))
            cv2.imshow('gt heatmap GENERATOR', np.sum(heatmaps, axis=-1))

            cv2.waitKey(0)  # FIXME

        # meta info
        metainfo = {
            'sample_index': sample_index,
            'tpts': kpanno,
            'name': imagefile
        }

        return norm_image, heatmaps, metainfo