def viewResult(sample,idx,prediction,config,save_images_instead=1,size=(384,384)):
    displays = []

    camera_idx = 0
    camera = sample['cameras'][camera_idx]
    subject = sample['subject'][camera_idx]
    action = sample['action'][camera_idx]

    keypoints3d_pred = prediction['keypoints_3d_pred'].cpu()
    keypoints_3d_pred = keypoints3d_pred[0,:, :3].detach().numpy()
    keypoints_3d_gt = sample['keypoints_3d'][:, :3]

    # Project and draw keypoints on images
    for camera_idx in range(len(sample['cameras'])): #camera_indexes_to_show:
        camera = sample['cameras'][camera_idx]

        keypoints_2d_pred = project(camera.projection, keypoints_3d_pred)
        keypoints_2d_gt = project(camera.projection, keypoints_3d_gt)

        # import ipdb; ipdb.set_trace()
        img = sample['images'][camera_idx]

        pred_kind = config.pred_kind if hasattr(config, "pred_kind") else config.kind
        display = vis.draw_2d_pose_cv2(keypoints_2d_pred, img, kind=pred_kind)
        #display = vis.draw_2d_pose_cv2(keypoints_2d_gt, img, kind=config.kind)
        cv2.putText(display, f"Cam {camera_idx:02}", (10, 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 0, 0))

        displays.append(display)

    display3 = vis.draw_3d_pose_image(keypoints_3d_pred,kind=pred_kind,radius=450)
    display3 = cv2.cvtColor(display3,cv2.COLOR_RGBA2RGB)
    display3 = cv2.resize(display3, size, interpolation=cv2.INTER_AREA)
    cv2.putText(display3, f"3D prediction", (10, 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 0, 0))
    displays.append(display3)

    display3_gt = vis.draw_3d_pose_image(sample['keypoints_3d'][:, :3],kind=pred_kind,radius=450)
    display3_gt = cv2.cvtColor(display3_gt,cv2.COLOR_RGBA2RGB)
    display3_gt = cv2.resize(display3_gt, size, interpolation=cv2.INTER_AREA)
    cv2.putText(display3_gt, f"3D GT", (10, 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 0, 0))
    displays.append(display3_gt)

    # Fancy stacked images
    for j, display in enumerate(displays):
        if j == 0:
            combined = display
        else:
            combined = np.concatenate((combined, display), axis=1)

    # Load
    if save_images_instead:
        file = f"./result/result-{subject}-{action}-{camera.name}-{idx}.png"
        cv2.imwrite(file, combined)   
    else:
        cv2.imshow('w', combined)
        cv2.setWindowTitle('w', f"Index {idx}")
        c = cv2.waitKey(0) % 256

        if c == ord('q') or c == 27:
            print('Quitting...')
            cv2.destroyAllWindows()
def viewVideoResult(sample,idx, prediction,config,size=(384,384)):
    displays = []

    keypoints3d_pred = prediction['keypoints_3d_pred'].cpu()
    keypoints_3d_pred = keypoints3d_pred[0,:, :3].detach().numpy()

    # Project and draw keypoints on images
    for camera_idx in range(len(sample['cameras'])): #camera_indexes_to_show:
        camera = sample['cameras'][camera_idx]

        keypoints_2d_pred = project(camera.projection, keypoints_3d_pred)

        # import ipdb; ipdb.set_trace()
        img = sample['images'][camera_idx]

        pred_kind = config.pred_kind if hasattr(config, "pred_kind") else config.kind
        display = vis.draw_2d_pose_cv2(keypoints_2d_pred, img, kind=pred_kind)
        cv2.putText(display, f"Cam {camera_idx:02}", (10, 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 0, 0))
        displays.append(display)

    display3 = vis.draw_3d_pose_image(keypoints_3d_pred,kind=pred_kind,radius=450)
    display3 = cv2.cvtColor(display3,cv2.COLOR_RGBA2RGB)
    display3 = cv2.resize(display3, size, interpolation=cv2.INTER_AREA)
    cv2.putText(display3, f"3D prediction", (10, 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 0, 0))
    displays.append(display3)

    # Fancy stacked images
    for j, display in enumerate(displays):
        if j == 0:
            combined = display
        else:
            combined = np.concatenate((combined, display), axis=1)

    return combined
def viewSample(sample,idx=0):
    camera_idx = 0
    image = sample['images'][camera_idx]
    camera = sample['cameras'][camera_idx]
    subject = sample['subject'][camera_idx]
    action = sample['action'][camera_idx]

    display = image.copy()
    keypoints_2d = project(camera.projection, sample['keypoints_3d'][:, :3])
    for i,(x,y) in enumerate(keypoints_2d):
        cv2.circle(display, (int(x), int(y)), 3, (0,0,255), -1)
    file = f"./result/{subject}-{action}-{camera.name}-{idx}.png"
    cv2.imwrite(file, display)
Esempio n. 4
0
patience = 0

sample_idx = 0  # number of sample to start from
step = 10  # in frames

while True:
    sample = dataset[sample_idx]

    camera_idx = 0
    image = sample['images'][camera_idx]
    camera = sample['cameras'][camera_idx]

    display = image.copy()

    from mvn.utils.multiview import project_3d_points_to_image_plane_without_distortion as project
    keypoints_2d = project(camera.projection, sample['keypoints_3d'][:, :3])

    for i, (x, y) in enumerate(keypoints_2d):
        cv2.circle(display, (int(x), int(y)), 3, (0, 0, 255), -1)
        # cv2.putText(display, str(i), (int(x)+3, int(y)), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0,0,255))

    # Get window name
    sample_info = dataset.labels['table'][sample_idx]
    subject_name = dataset.labels['subject_names'][sample_info['subject_idx']]
    action_name = dataset.labels['action_names'][sample_info['action_idx']]
    camera_name = dataset.labels['camera_names'][camera_idx]
    frame_idx = sample_info['frame_idx']

    cv2.imshow('w', display)
    cv2.setWindowTitle(
        'w', f"{subject_name}/{action_name}/{camera_name}/{frame_idx}")
print(img_dir)

camera_indexes_to_show = [0, 2, 8]

for i in range(0, len(indexes), n_images_step):
    labels = dataset[i]
    displays = []

    # Project and draw keypoints on images
    for camera_idx in range(len(labels['cameras'])):  #camera_indexes_to_show:
        camera = labels['cameras'][camera_idx]

        keypoints_3d_pred = keypoints3d_pred[i][:, :3]
        keypoints_3d_gt = labels['keypoints_3d'][:, :3]

        keypoints_2d_pred = project(camera.projection, keypoints_3d_pred)
        keypoints_2d_gt = project(camera.projection, keypoints_3d_gt)

        # import ipdb; ipdb.set_trace()

        img = labels['images'][camera_idx]

        pred_kind = config.pred_kind if hasattr(config,
                                                "pred_kind") else config.kind
        display = vis.draw_2d_pose_cv2(keypoints_2d_pred, img, kind=pred_kind)
        # display = vis.draw_2d_pose_cv2(keypoints_2d_gt, display, kind=config.kind)
        cv2.putText(display, f"Cam {camera_idx:02}", (10, 10),
                    cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 0, 0))

        displays.append(display)