STAR可视化代码(pytorch) —— hellostar.py

STAR可视化代码(pytorch) —— hellostar.py,第1张

STAR可视化代码(pytorch) —— hellostar.py
# with MPG or you get the right to use the computer program from someone who is authorized to grant you that right.
# Any use of the computer program without a valid license is prohibited and liable to prosecution.
# Contact: ps-license@tuebingen.mpg.de
#
#
# If you use this code in a research publication please consider citing the following:
#
# STAR: Sparse Trained  Articulated Human Body Regressor 
#
#
# Code Developed by:
# Ahmed A. A. Osman
from star.pytorch.star_model import STAR           # load model's parameters and return v_posed  
                                                   #  & transformed joints
import numpy as np
from numpy import newaxis
import pickle
import os
import torch

# beta contorls male model
betas = np.array([
            np.array([ 2.25176191, 2.25176191, 0.46747496, 3.89178988,
                      2.20098416, 0.26102114, 2.25176191, 0.55708514,
                      2.25176191, 2.25176191])])
num_betas=10
batch_size=1
#m = STAR(gender='male',num_betas=num_betas)

# Zero pose with female model
star = STAR(gender='female')
poses = torch.cuda.FloatTensor(np.zeros((batch_size,72)))
betas = torch.cuda.FloatTensor(betas)

trans = torch.cuda.FloatTensor(np.zeros((batch_size,3)))
verts = star.forward(poses, betas,trans)            # result model
verts=verts.tolist()                                # change data's structure from tensor to list 
faces = star.f                                      # faces is list so no need to change
shaped = verts.v_shaped[-1, :, :]                   # result model's v_posed

## Write to an .obj file
outmesh_path = '/home/xxw/Downloads/STAR-master/star/pytorch/hello_smpl.obj'
with open( outmesh_path, 'w') as fp:
    for v in range(len(verts[0])):                                           
        fp.write( 'v %f %f %fn' % (verts[0][v][0], verts[0][v][1], verts[0][v][2]) )

    for f in range(len(faces)): # Faces are 1-based, not 0-based in obj files
        fp.write( 'f %d %d %dn' %  (faces[f][0]+1, faces[f][1]+1, faces[f][2]+1) )

## Print message
print ('..Output mesh saved to: ', outmesh_path)

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5689551.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存