Пример #1
0
    def __getitem__(self, idx):
        if self.is_trian:
            ele_anno = self.anno[self.train_list[idx]]
        else:
            ele_anno = self.anno[self.valid_list[idx]]
        res_img = [256, 256]
        res_heatmap = [64, 64]
        path_img_folder = 'mpii_human_pose_v1/images'
        path_img = os.path.join(path_img_folder, ele_anno['img_paths'])
        img_origin = imgutils.load_image(path_img)

        img_crop, ary_pts_crop, c_crop = imgutils.crop(
            img_origin,
            ele_anno,
            use_randscale=self.use_scale,
            use_randflipLR=self.use_flip,
            use_randcolor=self.use_rand_color)

        img_out, pts_out, c_out = imgutils.change_resolu(
            img_crop, ary_pts_crop, c_crop, res_heatmap)

        train_img = skimage.transform.resize(img_crop, tuple(res_img))
        train_heatmap = imgutils.generate_heatmaps(img_out,
                                                   pts_out,
                                                   sigma_valu=2)
        train_pts = pts_out[:, :2].astype(np.int32)

        # (H,W,C) -> (C,H,W)
        train_img = np.transpose(train_img, (2, 0, 1))
        train_heatmap = np.transpose(train_heatmap, (2, 0, 1))

        return train_img, train_heatmap, train_pts
Пример #2
0

j = 0
for i, idx_train in enumerate(train_list):
    if i >= idx_begin and i <= idx_end:
        j += 1
        print(anno[idx_train])
        ele_anno = anno[idx_train]
        path_img = os.path.join(path_img_folder, ele_anno['img_paths'])
        print(path_img)
        img_origin = imgutils.load_image(path_img)
        # plt.figure(1)
        # plt.imshow(img_origin)
        # plt.show()
        img_crop, ary_pts_crop, c_crop = imgutils.crop_norescale(img_origin, ele_anno, use_randscale=False)
        img_out, pts_out, c_out = imgutils.change_resolu(img_crop, ary_pts_crop, c_crop, res_heatmap)
        heatmaps = imgutils.generate_heatmaps(img_out, pts_out, sigma_valu=2)
        # plt.figure(1)
        # plt.imshow(img_out)
        # plt.show()
        train_heatmaps[j - 1, ...] = heatmaps
        # plt.figure(1)
        # plt.imshow(train_heatmaps[j-1, :, :, 0])
        # plt.show()
        # imgutils.show_stack_joints(img_out, pts_out, c_out)
        # print('heatmaps.SHAPE', train_heatmaps[j - 1, ...].shape)
        # imgutils.show_heatmaps(img_out, train_heatmaps[j - 1, ...], c_out)
        print(len_idx, '/', j)


# Save train_imgs
Пример #3
0
with open('mpii_annotations.json') as anno_file:
    anno = json.load(anno_file)
for ele in anno:
    if ele['img_paths'] == '000678817.jpg':  #000033016, 000678817, 001834988
        ele_copy = ele
        print('FOUNDED')
        print(ele)

c_copy = ele_copy['objpos']
pts_copy = ele_copy['joint_self']

img_origin = imgutils.load_image('mpii_human_pose_v1/images/000678817.jpg')
img_copy = img_origin
# img_crop, ary_pts_crop, c_crop = imgutils.crop(img_origin, ele_copy)
img_crop, ary_pts_crop, c_crop = imgutils.crop_norescale(img_origin, ele_copy)
img_out, pts_out, c_out = imgutils.change_resolu(img_crop, ary_pts_crop,
                                                 c_crop, (256, 256))
heatmaps = imgutils.generate_heatmaps(img_out, pts_out, sigma_valu=7)

# img_out = imgutils.random_rotate(img_out)
# heatmaps = imgutils.random_rotate(heatmaps[:,:,:])

# img_out = imgutilsTF.random_flip_tf(img_out)
# heatmaps = imgutilsTF.random_flip_tf(heatmaps[:,:,:])

# Show image and heatmaps
imgutils.show_stack_joints(img_out, pts_out, c_out)
# imgutils.show_heatmaps(img_out, heatmaps, c_out)

# plt.figure(1)
# plt.imshow(img_out)
# plt.show()