Exemplo n.º 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
    def process_image(self, sample_index, kpanno, sigma):
        imagefile = kpanno['img_path']
        image = scipy.misc.imread(os.path.join(self.imgpath, imagefile))

        if image.ndim < 3:
            image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)

        # get center
        bb = np.array(kpanno['face'])
        kp = np.array(kpanno['landmarks'])


        cropimg = data_process.crop(image, bb, (224, 224))
        #cropimg = data_process.normalize(cropimg, self.get_color_mean())

        # transform keypoints
        transformed_kp = data_process.transform_kp(image, bb, kp, (224, 224))
        gtmap = data_process.generate_hm((224, 224), transformed_kp, 3)

        return np.swapaxes(cropimg, 0, 2), np.swapaxes(gtmap, 0, 2)
Exemplo n.º 3
0
def view_crop_image(anno):

    print anno.keys()

    img_paths = anno['img_paths']
    img_width = anno['img_width']
    img_height = anno['img_height']

    #print anno.keys()

    imgdata = scipy.misc.imread(
        os.path.join("../../data/mpii/images", img_paths))
    draw_joints(imgdata, anno['joint_self'])
    #scipy.misc.imshow(imgdata)

    center = np.array(anno['objpos'])
    outimg = data_process.crop(imgdata,
                               center=center,
                               scale=anno['scale_provided'],
                               res=(256, 256),
                               rot=0)
    outimg_normalized = data_process.normalize(outimg)

    print outimg.shape

    newjoints = data_process.transform_kp(np.array(anno['joint_self']),
                                          center,
                                          anno['scale_provided'], (64, 64),
                                          rot=0)
    #draw_joints(outimg_normalized, newjoints.tolist())
    #scipy.misc.imshow(outimg_normalized)
    '''
    mimage = np.zeros(shape=(64, 64), dtype=np.float)
    gtmap = generate_gt_map(newjoints, sigma=1, outres=(64, 64))
    for i in range(16):
        mimage += gtmap[:, :, i]
    scipy.misc.imshow(mimage)
    '''

    # meta info
    metainfo = []
    orgjoints = np.array(anno['joint_self'])
    for i in range(newjoints.shape[0]):
        meta = {
            'center': center,
            'scale': anno['scale_provided'],
            'pts': orgjoints[i],
            'tpts': newjoints[i]
        }
        metainfo.append(meta)

    # transform back
    tpbpts = list()
    for i in range(newjoints.shape[0]):
        tpts = newjoints[i]
        meta = metainfo[i]
        orgpts = tpts
        orgpts[0:2] = data_process.transform(tpts,
                                             meta['center'],
                                             meta['scale'],
                                             res=[64, 64],
                                             invert=1,
                                             rot=0)
        tpbpts.append(orgpts)

    print tpbpts

    draw_joints(imgdata, np.array(tpbpts))
    scipy.misc.imshow(imgdata)