def __init__(self, image_folder, frames, bboxes=None, joints2d=None, scale=1.0, crop_size=224): self.image_file_names = [ osp.join(image_folder, x) for x in os.listdir(image_folder) if x.endswith('.png') or x.endswith('.jpg') ] self.image_file_names = sorted(self.image_file_names) self.image_file_names = np.array(self.image_file_names)[frames] self.bboxes = bboxes self.joints2d = joints2d self.scale = scale self.crop_size = crop_size self.frames = frames self.has_keypoints = True if joints2d is not None else False self.norm_joints2d = np.zeros_like(self.joints2d) if self.has_keypoints: bboxes, time_pt1, time_pt2 = get_all_bbox_params(joints2d, vis_thresh=0.3) bboxes[:, 2:] = 150. / bboxes[:, 2:] self.bboxes = np.stack( [bboxes[:, 0], bboxes[:, 1], bboxes[:, 2], bboxes[:, 2]]).T self.image_file_names = self.image_file_names[time_pt1:time_pt2] self.joints2d = joints2d[time_pt1:time_pt2] self.frames = frames[time_pt1:time_pt2]
def __init__(self, images, frames, bboxes=None, joints2d=None, scale=1.0, crop_size=224): self.images = images self.bboxes = bboxes self.joints2d = joints2d self.scale = scale self.crop_size = crop_size self.frames = frames self.has_keypoints = True if joints2d is not None else False self.norm_joints2d = np.zeros_like(self.joints2d) if self.has_keypoints: bboxes, time_pt1, time_pt2 = get_all_bbox_params(joints2d, vis_thresh=0.3) bboxes[:, 2:] = 150. / bboxes[:, 2:] self.bboxes = np.stack( [bboxes[:, 0], bboxes[:, 1], bboxes[:, 2], bboxes[:, 2]]).T self.images = self.images[time_pt1:time_pt2] self.joints2d = joints2d[time_pt1:time_pt2] self.frames = frames[time_pt1:time_pt2]
def preprocess_video(video, joints2d, bboxes, frames, scale=1.0, crop_size=224): """ Read video, do normalize and crop it according to the bounding box. If there are bounding box annotations, use them to crop the image. If no bounding box is specified but openpose detections are available, use them to get the bounding box. :param video (ndarray): input video :param joints2d (ndarray, NxJx3): openpose detections :param bboxes (ndarray, Nx5): bbox detections :param scale (float): bbox crop scaling factor :param crop_size (int): crop width and height :return: cropped video, cropped and normalized video, modified bboxes, modified joints2d """ if joints2d is not None: bboxes, time_pt1, time_pt2 = get_all_bbox_params(joints2d, vis_thresh=0.3) bboxes[:, 2:] = 150. / bboxes[:, 2:] bboxes = np.stack( [bboxes[:, 0], bboxes[:, 1], bboxes[:, 2], bboxes[:, 2]]).T video = video[time_pt1:time_pt2] joints2d = joints2d[time_pt1:time_pt2] frames = frames[time_pt1:time_pt2] shape = video.shape temp_video = np.zeros((shape[0], crop_size, crop_size, shape[-1])) norm_video = torch.zeros(shape[0], shape[-1], crop_size, crop_size) for idx in range(video.shape[0]): img = video[idx] bbox = bboxes[idx] j2d = joints2d[idx] if joints2d is not None else None norm_img, raw_img, kp_2d = get_single_image_crop_demo( img, bbox, kp_2d=j2d, scale=scale, crop_size=crop_size) if joints2d is not None: joints2d[idx] = kp_2d temp_video[idx] = raw_img norm_video[idx] = norm_img temp_video = temp_video.astype(np.uint8) return temp_video, norm_video, bboxes, joints2d, frames
def __init__(self, image_folder, bboxes=None, joints2d=None, scale=1.0, crop_size=224): self.image_file_names = [ osp.join(image_folder, x) for x in os.listdir(image_folder) if x.endswith('.png') or x.endswith('.jpg') ] self.image_file_names = sorted(self.image_file_names) frames = [x for x in range(len(self.image_file_names))] self.image_file_names = np.array(self.image_file_names)[frames] print('#######################', self.image_file_names, '#########################') self.bboxes = bboxes self.scale = scale self.crop_size = crop_size self.frames = frames self.has_keypoints = True #if joints2d is not None else False #self.norm_joints2d = np.zeros_like(self.joints2d) self.annotation_path = image_folder + '/fitted.npy' self.data = np.load(self.annotation_path, encoding='latin1', allow_pickle=True).item() self.joints2d = [ self.data[textED(key)]['p2d'] for key in self.image_file_names ] self.pose = np.asarray([ self.data[textED(key)]['fitting_params']['pose'] for key in self.image_file_names ]) # 3d keypoints self.skeleton_smpl = np.asarray([ self.data[textED(key)]['fitting_params']['v'] for key in self.image_file_names ]) self.cam_t = np.asarray([ self.data[textED(key)]['fitting_params']['cam_t'] for key in self.image_file_names ]) #print('&&&&&&&&&&&3D SHAPE------',self.pose.shape) joints2d = np.asarray(self.joints2d) ones = np.ones((joints2d.shape[0], joints2d.shape[1], 3)) ones[:, :, :2] = joints2d self.joints2d = ones #np.concatenate( (self.joints2d, np.ones( (len(self.joints2d),1) ) ), axis=1) #print('2d GT shape-----------',self.joints2d.shape) #print('2d GT -------------',joints2d) if self.has_keypoints: bboxes, time_pt1, time_pt2 = get_all_bbox_params(self.joints2d, vis_thresh=0.3) #print('box shape',bboxes) bboxes[:, 2:] = 150. / bboxes[:, 2:] self.bboxes = np.stack( [bboxes[:, 0], bboxes[:, 1], bboxes[:, 2], bboxes[:, 2]]).T #print('bboxes---',self.bboxes) self.image_file_names = self.image_file_names[time_pt1:time_pt2] self.joints2d = joints2d[time_pt1:time_pt2] self.frames = frames[time_pt1:time_pt2]