zhixuany / HUMBI

This repository contains official code (in MATLAB) for exploring and visualizing HUMBI dataset introduced in the paper "HUMBI: A Large Multiview Dataset of Human Body Expressions" (CVPR 2020).
MIT License
117 stars 8 forks source link

Questions about projection of provided 3D keypoints #20

Open sunwonlikeyou opened 3 years ago

sunwonlikeyou commented 3 years ago

I want to see 2D keypoints of certain frame on images so i did projection processing. but i got wrong result. what's the matter?? As i know about getting 2D points is {2D keypoints = homogeneous(projection matrix * 3D keypoints)} Could you tell me what's the problem...?? More details about my code: i want to see image0000000.jpg & projected 2D keypoints each frame.

import torch
import numpy as np
from lib.models.smpl import SMPL
import os
import pdb
sub_path = '/Body_1_80_updat/subject_1/body/'
frames = os.listdir(sub_path)[:-4]
proj = open(sub_path+'project.txt','r').readlines()

projection = np.zeros((107,3,4))
extrinsic = np.zeros((107,3,4))
intrinsic = np.zeros((107,3,3))
cam_KR = np.zeros((107,3,4))
for i in range(len(projection)):
    projection[i,0] = np.array(proj[4+4*i].split(),dtype=np.float32)
    projection[i, 1] = np.array(proj[5 + 4*i].split(),dtype=np.float32)
    projection[i, 2] = np.array(proj[6 + 4*i].split(),dtype=np.float32)

import cv2

imglist = list(range(107))
for frame in frames:
    img_path =  '/Body_1_80_updat/subject_1/body/%s/image/'%frame
    img_list = os.listdir(img_path)
    keypoints_path ='/Body_1_80_updat/subject_1/body/%s/reconstruction/keypoints.txt'%frame
    keypoints_3d= np.loadtxt(keypoints_path).reshape(-1,3)
    dummy = np.ones((len(keypoints_3d), 1))
    kpts = np.concatenate((keypoints_3d, dummy), axis=1)
    kpts = np.matmul(kpts, projection[0].T)
    kpts = kpts[:,:2]/kpts[:,2].reshape(-1,1)

    img = cv2.imread(img_path+img_list[0])
    for joint in kpts:
        cv2.circle(img, (int(joint[0]),int(joint[1])),10,(255,0,0),-1)

    img = cv2.resize(img, (512,512))
    cv2.imshow('img', img)
    k = cv2.waitKey()
    if k == 27:
        cv2.destroyAllWindows()

image

masonwang513 commented 1 year ago

@sunwonlikeyou There are mistakes in your code. Just fix like this: kpts = np.concatenate((keypoints_3d, dummy), axis=1) # [25, 4] kpts = np.matmul(projection[0], kpts.T).T # [3, 4] x [4, 25] --> [3, 25] --> [25, 3] kpts = kpts[:,:2]/kpts[:,2].reshape(-1,1)