Exemplo n.º 1
0
def Inference(frame, bboxes=None, scale=1.0, crop_size=224):
    img = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
    norm_img, raw_img, kp_2d = get_single_image_crop_demo(img,
                                                          bboxes[0],
                                                          kp_2d=None,
                                                          scale=scale,
                                                          crop_size=crop_size)
    #norm_img = norm_img/255. #TODO 可能会有多张图片
    return norm_img
Exemplo n.º 2
0
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
Exemplo n.º 3
0
    def __getitem__(self, idx):
        img = cv2.cvtColor(cv2.imread(self.image_file_names[idx]),
                           cv2.COLOR_BGR2RGB)
        #cv2.imwrite(f"/home/ubuntu/gyrus/3D_pose/myimg{idx}.jpg",img)
        bbox = self.bboxes[idx]

        j2d = self.joints2d[idx] if self.has_keypoints else None

        norm_img, raw_img, kp_2d = get_single_image_crop_demo(
            img, bbox, kp_2d=j2d, scale=self.scale, crop_size=self.crop_size)

        #print('inside custom data',j2d.shape,kp_2d.shape)
        #print('crop 2d points==',kp_2d[:2],'org 2d key pt',j2d[:2])
        #print('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$2d key point shaep---',kp_2d.tolist())
        # cv_keypoints =[]
        # for x,y in kp_2d.tolist():
        #     cv_keypoints.append(cv2.KeyPoint(x, y,10))
        # cv2.drawKeypoints(raw_img, cv_keypoints, raw_img, color=(255,0,0))
        # c=0
        # for x,y in kp_2d.tolist():
        #     cv2.putText(raw_img, f"{c}", (int(x), int(y)), cv2.FONT_HERSHEY_SIMPLEX, 0.4, (255,150,250), 1)
        #     c+=1
        # cv2.imwrite(f"/home/ubuntu/gyrusWork/myimg{idx}.jpg",raw_img)

        self.skeleton_smpl = self.skeleton_smpl[idx].reshape(-1, 3)

        print('v shape in custom data####', self.skeleton_smpl.shape)
        skeleton1 = np.zeros((32, 3))

        #skeleton1[USE_DIMS] = self.skeleton_smpl[H36M_IDS]

        H36M_IDS = [
            8, 5, 2, 1, 4, 7, 21, 19, 17, 16, 18, 20, 12, 15, 3, 12, 15
        ]

        print('skeleton shape', self.skeleton_smpl.shape)

        skeleton = self.skeleton_smpl[H36M_IDS]

        #print('$$$$$3d sekelon shape',skeleton.reshape(-1).shape)

        #print('debug2%%%%',img.shape,type(img))

        visualize(skeleton.reshape(-1), skeleton, img, t=self.cam_t[idx])

        KP3d = skeleton.reshape(-1, 3)
        #print('xxxxxxxxxxxxxxxxxxx',KP3d.shape)

        if self.has_keypoints:
            return norm_img, kp_2d, self.pose[
                idx], bbox, raw_img, img, KP3d, self.cam_t[idx]
        else:
            return norm_img
Exemplo n.º 4
0
    def __getitem__(self, idx):
        img = cv2.cvtColor(cv2.imread(self.image_file_names[idx]),
                           cv2.COLOR_BGR2RGB)

        bbox = self.bboxes[idx]

        j2d = self.joints2d[idx] if self.has_keypoints else None

        norm_img, raw_img, kp_2d = get_single_image_crop_demo(
            img, bbox, kp_2d=j2d, scale=self.scale, crop_size=self.crop_size)
        if self.has_keypoints:
            return norm_img, kp_2d
        else:
            return norm_img
Exemplo n.º 5
0
    def __getitem__(self, idx):

        bbox = self.bboxes[idx]

        j2d = self.joints2d[idx] if self.has_keypoints else None

        norm_img, raw_img, kp_2d = get_single_image_crop_demo(
            self.images[idx],
            bbox,
            kp_2d=j2d,
            scale=self.scale,
            crop_size=self.crop_size)
        if self.has_keypoints:
            return norm_img, kp_2d
        else:
            return norm_img