"""
Copyright 2016 Max Planck Society, Federica Bogo, Angjoo Kanazawa. All rights reserved.
This software is provided for research purposes only.
By using this software you agree to the terms of the SMPLify license here:
http://smplify.is.tue.mpg.de/license
About this Script:
============
This is a demo version of the algorithm implemented in the paper,
which fits the SMPL body model to the image given the joint detections.
The code is organized to be run on the LSP dataset.
See README to see how to download images and the detected joints.
"""
from os.path import join, exists, abspath, dirname
from os import makedirs
import logging
import pickle
# import cPickle as pickle
from time import time
from glob import glob
import argparse
import cv2
import numpy as np
import chumpy as ch
from opendr.camera import ProjectPoints
from lib.robustifiers import GMOf
from smpl_webuser.serialization import load_model
from smpl_webuser.lbs import global_rigid_transformation
from smpl_webuser.verts import verts_decorated
from lib.sphere_collisions import SphereCollisions
from lib.max_mixture_prior import MaxMixtureCompletePrior
from render_model import render_model
_LOGGER = logging.getLogger(__name__)
# Mapping from LSP joints to SMPL joints.
# 0 Right ankle 8
# 1 Right knee 5
# 2 Right hip 2
# 3 Left hip 1
# 4 Left knee 4
# 5 Left ankle 7
# 6 Right wrist 21
# 7 Right elbow 19
# 8 Right shoulder 17
# 9 Left shoulder 16
# 10 Left elbow 18
# 11 Left wrist 20
# 12 Neck -
# 13 Head top added
# --------------------Camera estimation --------------------
def guess_init(model, focal_length, j2d, init_pose):
"""Initialize the camera translation via triangle similarity, by using the torso joints .
:param model: SMPL model
:param focal_length: camera focal length (kept fixed)
:param j2d: 14x2 array of CNN joints
:param init_pose: 72D vector of pose parameters used for initialization (kept fixed)
:returns: 3D vector corresponding to the estimated camera translation
"""
cids = np.arange(0, 12)
# map from LSP to SMPL joints
j2d_here = j2d[cids]
smpl_ids = [8, 5, 2, 1, 4, 7, 21, 19, 17, 16, 18, 20]
opt_pose = ch.array(init_pose)
(_, A_global) = global_rigid_transformation(
opt_pose, model.J, model.kintree_table, xp=ch)
Jtr = ch.vstack([g[:3, 3] for g in A_global])
Jtr = Jtr[smpl_ids].r
# 9 is L shoulder, 3 is L hip
# 8 is R shoulder, 2 is R hip
diff3d = np.array([Jtr[9] - Jtr[3], Jtr[8] - Jtr[2]])
mean_height3d = np.mean(np.sqrt(np.sum(diff3d**2, axis=1)))
diff2d = np.array([j2d_here[9] - j2d_here[3], j2d_here[8] - j2d_here[2]])
mean_height2d = np.mean(np.sqrt(np.sum(diff2d**2, axis=1)))
est_d = focal_length * (mean_height3d / mean_height2d)
# just set the z value
init_t = np.array([0., 0., est_d])
return init_t
def initialize_camera(model,
j2d,
img,
init_pose,
flength=5000.,
pix_thsh=25.,
viz=False):
"""Initialize camera translation and body orientation
:param model: SMPL model
:param j2d: 14x2 array of CNN joints
:param img: h x w x 3 image
:param init_pose: 72D vector of pose parameters used for initialization
:param flength: camera focal length (kept fixed)
:param pix_thsh: threshold (in pixel), if the distance between shoulder joints in 2D
is lower than pix_thsh, the body orientation as ambiguous (so a fit is run on both
the estimated one and its flip)
:param viz: boolean, if True enables visualization during optimization
:returns: a tuple containing the estimated camera,
a boolean deciding if both the optimized body orientation and its flip should be considered,
3D vector for the body orientation
"""
# optimize camera translation and body orientation based on torso joints
# LSP torso ids:
# 2=right hip, 3=left hip, 8=right shoulder, 9=left shoulder
torso_cids = [2, 3, 8, 9]
# corresponding SMPL torso ids
torso_smpl_ids = [2, 1, 17, 16]
center = np.array([img.shape[1] / 2, img.shape[0] / 2])
# initialize camera rotation
rt = ch.zeros(3)
# initialize camera translation
_LOGGER.info('initializing translation via similar triangles')
init_t = guess_init(model, flength, j2d, init_pose)
t = ch.array(init_t)
# check how close the shoulder joints are
try_both_orient = np.linalg.norm(j2d[8] - j2d[9]) < pix_thsh
opt_pose = ch.array(init_pose)
(_, A_global) = global_rigid_transformation(
opt_pose, model.J, model.kintree_table, xp=ch)
Jtr = ch.vstack([g[:3, 3] for g in A_global])
# initialize the camera
cam = ProjectPoints(
f=np.array([flength, flength]), rt=rt, t=t, k=np.zeros(5), c=center)
# we are going to project the SMPL joints
cam.v = Jtr
if viz:
viz_img = img.copy()
# draw the target (CNN) joints
for coord in np.around(j2d).astype(int):
if (coord[0] < img.shape[1] and coord[0] >= 0 and
coord[1] < img.shape[0] and coord[1] >= 0):
cv2.circle(viz_img, tuple(coord), 3, [0, 255, 0])
import matplotlib.pyplot as plt
plt.ion()
# draw optimized joints at each iteration
def on_step(_):
"""Draw a visualization."""
plt.figure(1, figsize=(5, 5))
plt.subplot(1, 1, 1)
viz_img = img.copy()
for coord in np.around(cam.r[torso_smpl_ids]).astype(int):
if (coord[0] < viz_img.shape[1] and coord[0] >= 0 and
coord[1] < viz_img.shape[0] and coord[1] >= 0):
cv2.circle(viz_img, tuple(coord), 3, [0, 0, 255])
plt.imshow(viz_img[:, :, ::-1])
plt.draw()
plt.show()
plt.pause(1e-3)
else:
on_step = None
# optimize for camera translation and body orientation
free_variables = [cam.t, opt_pose[:3]]
ch.minimize(
# data term defined over torso joints...
{'cam': j2d[torso_cids] - cam[torso_smpl_ids],
# ...plus a regularizer for the camera translation
'cam_t': 1e2 * (cam.t[2] - init_t[2])},
x0=free_variables,
method='dogleg',
callback=on_step,
options={'maxiter': 100,
'e_3': .0001,
# disp set to 1 enables verbose output from the optimizer
'disp': 0})
if viz:
plt.ioff()
return (cam, try_both_orient, opt_pose[:3].r)
# --------------------Core optimization --------------------
def optimize_on_joints(j2d,
model,
cam,
img,
prior,
try_both_orient,
body_orient,
n_betas=10,
regs=None,
conf=None,
viz=False):
"""Fit the model to the given set of joints, given the estimated camera
:param j2d: 14x2 array of CNN joints
:param model: SMPL model
:param cam: estimated camera
:param img: h x w x 3 image
:param prior: mixture of gaussians pose prior
:param try_both_orient: boolean, if True both body_orient and its flip are considered for the fit
:param body_orient: 3D vector, initialization for the body orientation
:param n_betas: number of shape coefficients considered during optimization
:param regs: regressors for capsules' axis and radius, if not None enables the interpenetration error term
:param conf: 14D vector storing the confidence values from the CNN
:param viz: boolean, if True enables visualization during optimization
:returns: a tuple containing the optimized model, its joints projected on image space,
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【资源说明】 课设项目-基于python实现的人体动作捕捉与三维重建源码+操作说明.zip 进入 `code` 目录: ```bashrc $ sudo apt-get install libosmesa6-dev $ pip3 install opendr==0.78 $ pip3 install pyrender trimesh ``` ## 运行 smpl ```bashrc $ cd code $ python hello_smpl.py ``` ## 运行 smplify ```bashrc $ cd code $ python fit_3d.py ``` 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载使用,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可直接用于毕设、课设、作业等。 欢迎下载,沟通交流,互相学习,共同进步!
资源推荐
资源详情
资源评论
收起资源包目录
课设项目-基于python实现的人体动作捕捉与三维重建源码+操作说明.zip (2000个子文件)
im0793.jpg 14KB
im1824.jpg 13KB
im1160.jpg 12KB
im1246.jpg 11KB
im1248.jpg 11KB
im1176.jpg 11KB
im0607.jpg 11KB
im0407.jpg 11KB
im1745.jpg 10KB
im1302.jpg 10KB
im0136.jpg 10KB
im0560.jpg 10KB
im1841.jpg 10KB
im1069.jpg 10KB
im0963.jpg 10KB
im0222.jpg 10KB
im1142.jpg 10KB
im1924.jpg 10KB
im1362.jpg 10KB
im0705.jpg 10KB
im1746.jpg 9KB
im0589.jpg 9KB
im1885.jpg 9KB
im0175.jpg 9KB
im1607.jpg 9KB
im1117.jpg 9KB
im1840.jpg 9KB
im0543.jpg 9KB
im1657.jpg 9KB
im1962.jpg 9KB
im1685.jpg 9KB
im1423.jpg 9KB
im1308.jpg 9KB
im1316.jpg 9KB
im1878.jpg 9KB
im1980.jpg 9KB
im0228.jpg 9KB
im1809.jpg 9KB
im0369.jpg 9KB
im0178.jpg 9KB
im1104.jpg 9KB
im0922.jpg 9KB
im0359.jpg 9KB
im0372.jpg 9KB
im0026.jpg 9KB
im1709.jpg 9KB
im1682.jpg 9KB
im1132.jpg 9KB
im0115.jpg 9KB
im1098.jpg 9KB
im0449.jpg 9KB
im1729.jpg 9KB
im1049.jpg 9KB
im0430.jpg 9KB
im1027.jpg 9KB
im0384.jpg 9KB
im1643.jpg 9KB
im0999.jpg 9KB
im0192.jpg 9KB
im1260.jpg 9KB
im0498.jpg 9KB
im0576.jpg 9KB
im1777.jpg 9KB
im1456.jpg 9KB
im0336.jpg 9KB
im0016.jpg 9KB
im1843.jpg 9KB
im0293.jpg 9KB
im0153.jpg 9KB
im0928.jpg 9KB
im1979.jpg 9KB
im1540.jpg 8KB
im0886.jpg 8KB
im0008.jpg 8KB
im0775.jpg 8KB
im1848.jpg 8KB
im0238.jpg 8KB
im1581.jpg 8KB
im0021.jpg 8KB
im0595.jpg 8KB
im1367.jpg 8KB
im0851.jpg 8KB
im0693.jpg 8KB
im1835.jpg 8KB
im0953.jpg 8KB
im1331.jpg 8KB
im0679.jpg 8KB
im0250.jpg 8KB
im1041.jpg 8KB
im1002.jpg 8KB
im1813.jpg 8KB
im0936.jpg 8KB
im0802.jpg 8KB
im1526.jpg 8KB
im1918.jpg 8KB
im0274.jpg 8KB
im1922.jpg 8KB
im1495.jpg 8KB
im0986.jpg 8KB
im0247.jpg 8KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
- qq_539434132024-03-23资源内容详实,描述详尽,解决了我的问题,受益匪浅,学到了。
onnx
- 粉丝: 1w+
- 资源: 5627
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 工具变量-中国省级新质生产力数据(2010-2023年).xlsx
- 工具变量-中国省级新质生产力数据(2010-2023年).dta
- linux批量配置防火墙脚本firewall.sh
- jdk8 开发者中文手册
- CANoe中如何定义 <结构体数组> 类型的系统变量
- 一个用 Python 实现的猜数字游戏源码,玩家需要在一定范围内猜出程序预设的数字,程序会根据玩家的猜测给出提示,直到玩家猜对为止
- ESP8266+OLED实时显示天气和时间
- 基于CAPL内置函数,提取DBC报文信号属性信息
- 特别推荐的是 mysqlclient-1.4.6-cp37-cp37m-win-amd64.whl 文件等,专为 Windows 64 位系统下的 Python 3.6 3.7 3.8 环境设计
- flink siddhi 资源jar包,flink与siddhi集成,实现对复杂事件的处理 在flink中直接引入即可
- 多领域视角下的Cursor概念解析:数据库、GUI和编程中的应用及作用
- 一个使用 Python 进行数据分析的源码,它读取一个包含学生成绩的 CSV 文件,计算每个学生的平均成绩,并找出平均成绩最高的学生
- es 8.17.0 apache-skywalking-apm-10.1.0,同时配合elasticsearch-8.17.0-windows-x86-64来作为存储 es持久化数据使用
- MySQL 安装与配置详细步骤介绍及用途
- 计算机视觉中YOLOv11的目标检测技术创新及广泛应用
- apache-skywalking-apm-10.1.0 elasticsearch-8.17.0-windows-x86-64andapache-skywalking-apm-10.1.0
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功