JiantaoLin
commited on
Commit
·
6dafd85
1
Parent(s):
3063c92
new
Browse files- video_render.py +14 -3
video_render.py
CHANGED
@@ -22,6 +22,15 @@ from pytorch3d.transforms import RotateAxisAngle
|
|
22 |
|
23 |
from shader import MultiOutputShader
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
def render_video_from_obj(input_obj_path, output_video_path, num_frames=60, image_size=512, fps=15, device="cuda"):
|
26 |
if not os.path.exists(input_obj_path):
|
27 |
raise FileNotFoundError(f"Input OBJ file not found: {input_obj_path}")
|
@@ -87,12 +96,14 @@ def render_video_from_obj(input_obj_path, output_video_path, num_frames=60, imag
|
|
87 |
cameras=cameras,
|
88 |
lights=lights,
|
89 |
materials=materials,
|
90 |
-
choices=["rgb", "mask", "normal"]
|
91 |
)
|
92 |
|
93 |
renderer = MeshRenderer(rasterizer=rasterizer, shader=shader)
|
94 |
render_result = renderer(mesh, cameras=cameras)
|
95 |
-
|
|
|
|
|
96 |
normal_map = render_result["normal"]
|
97 |
|
98 |
rgb = rgb_image[0, ..., :3].cpu().numpy()
|
@@ -111,6 +122,6 @@ def render_video_from_obj(input_obj_path, output_video_path, num_frames=60, imag
|
|
111 |
print(f"Video saved to {output_video_path}")
|
112 |
|
113 |
if __name__ == '__main__':
|
114 |
-
input_obj_path = "
|
115 |
output_video_path = "output.mp4"
|
116 |
render_video_from_obj(input_obj_path, output_video_path)
|
|
|
22 |
|
23 |
from shader import MultiOutputShader
|
24 |
|
25 |
+
def _rgb_to_srgb(f: torch.Tensor) -> torch.Tensor:
|
26 |
+
return torch.where(f <= 0.0031308, f * 12.92, torch.pow(torch.clamp(f, 0.0031308), 1.0/2.4)*1.055 - 0.055)
|
27 |
+
|
28 |
+
def rgb_to_srgb(f: torch.Tensor) -> torch.Tensor:
|
29 |
+
assert f.shape[-1] == 3 or f.shape[-1] == 4
|
30 |
+
out = torch.cat((_rgb_to_srgb(f[..., 0:3]), f[..., 3:4]), dim=-1) if f.shape[-1] == 4 else _rgb_to_srgb(f)
|
31 |
+
assert out.shape[0] == f.shape[0] and out.shape[1] == f.shape[1]
|
32 |
+
return out
|
33 |
+
|
34 |
def render_video_from_obj(input_obj_path, output_video_path, num_frames=60, image_size=512, fps=15, device="cuda"):
|
35 |
if not os.path.exists(input_obj_path):
|
36 |
raise FileNotFoundError(f"Input OBJ file not found: {input_obj_path}")
|
|
|
96 |
cameras=cameras,
|
97 |
lights=lights,
|
98 |
materials=materials,
|
99 |
+
choices=["rgb", "mask", "normal", "albedo"]
|
100 |
)
|
101 |
|
102 |
renderer = MeshRenderer(rasterizer=rasterizer, shader=shader)
|
103 |
render_result = renderer(mesh, cameras=cameras)
|
104 |
+
|
105 |
+
render_result["albedo"] = rgb_to_srgb(render_result["albedo"]/255.0)*255.0
|
106 |
+
rgb_image = render_result["albedo"] * render_result["mask"] + (1 - render_result["mask"]) * torch.ones_like(render_result["albedo"]) * 255.0
|
107 |
normal_map = render_result["normal"]
|
108 |
|
109 |
rgb = rgb_image[0, ..., :3].cpu().numpy()
|
|
|
122 |
print(f"Video saved to {output_video_path}")
|
123 |
|
124 |
if __name__ == '__main__':
|
125 |
+
input_obj_path = "./354e2aee-091d-4dc6-bdb1-e09be5791218_isomer_recon_mesh.obj"
|
126 |
output_video_path = "output.mp4"
|
127 |
render_video_from_obj(input_obj_path, output_video_path)
|