Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Questions about projection of provided 3D keypoints #20

Open
sunwonlikeyou opened this issue Apr 22, 2021 · 1 comment
Open

Questions about projection of provided 3D keypoints #20

sunwonlikeyou opened this issue Apr 22, 2021 · 1 comment

Comments

@sunwonlikeyou
Copy link

sunwonlikeyou commented Apr 22, 2021

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
Copy link

@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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants