forked from yuki-koyama/blender-cli-rendering
-
Notifications
You must be signed in to change notification settings - Fork 2
/
render_human_pose.py
52 lines (49 loc) · 2.53 KB
/
render_human_pose.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import subprocess
from typing import Optional
def render_pose(
pose: list[list[float]],
joint_links: list[list[int]],
color: tuple[float, float, float] = (0.1, 0.2, 0.6),
gt_pose: Optional[list[list[float]]] = None,
gt_joint_links: Optional[list[list[int]]] = None,
gt_color: Optional[tuple[float, float, float]] = (0.6, 0.1, 0.2),
output_path: str = "./output/pose",
resolution_percentage: int = 100,
samplings: int = 128,
blender_path: str = "blender",
gui: bool = False,
):
"""The method to use from your project to render poses.
Calls this script with required args using blender cli.
Args:
pose (list[list[float]]): List of x,y,z, of joints.
joint_links (list[list[int]]): List of connections between joints.
color (tuple[float, float, float], optional): RGB (0-1 scale) color for skeleton. Defaults to (0.1, 0.2, 0.6).
gt_pose (Optional[list[list[float]]], optional): Pose for comparison. Defaults to None.
gt_joint_links (Optional[list[list[int]]]): List of connections between joints for GT pose, probably same as `joint_links`.
gt_color (Optional[tuple[float, float, float]], optional): RGB (0-1 scale) for GT skeleton. Defaults to (0.6, 0.1, 0.2).
output_path (str, optional): Save dir path or file name. Defaults to "./output/pose".
resolution_percentage (int, optional): Percentage of resolution (1080). Defaults to 100.
samplings (int, optional): Samples during rendering. Defaults to 128.
blender_path (str, optional): Blender exec path. Defaults to "blender".
gui (bool, optional): Run with gui, for experimentation and debugging. Defaults to False.
"""
script_path = "human_pose.py"
cmd_parts = [
blender_path,
"--background" if not gui else "",
f"--python {script_path}",
"--render-frame 1",
"--", # Blender ignore the args following this.
f"--pose '{(list(pose))}'",
f"--joint_links '{(list(joint_links))}'",
f"--color {color[0]} {color[1]} {color[2]}" if color else "",
f"--gt_pose '{(list(gt_pose))}'" if gt_pose is not None else "",
f"--gt_joint_links '{(list(gt_joint_links))}'" if gt_joint_links is not None else "",
f"--gt_color {gt_color[0]} {gt_color[1]} {gt_color[2]}" if gt_color else "",
f"--output_path {output_path}",
f"--resolution_percentage {resolution_percentage}",
f"--samplings {samplings}",
]
command = " ".join(cmd_parts)
_ = subprocess.call(command, shell=True)