def render_lsd(seq): plypath = os.path.join(seq, 'render_me.ply') verts, edges = IO.read_ply(plypath) lsd_mesh = Mesh() lsd_mesh.verts = verts.astype(np.float32) campath = os.path.join(seq, 'render.py') Rs, ts = IO.import_blender_cam(campath) W, H = 1920, 1080 im = empty((H, W, 3), np.uint8) cam = Geom.cam_params(29.97, W, H, 35) # Blender defaults cam = cam.astype(np.float32) render_out = os.path.join(seq, 'render') Util.try_mkdir(render_out) im[:] = 255 pts = lsd_mesh.project_verts(Rs[0].astype(np.float32), ts[0].astype(np.float32), cam) pt_buf = buffer_points(pts, np.r_[255, 82, 82], alpha=0.2, size=2) render_buffer(im, pt_buf, bg=255) out = os.path.join(render_out, 'frame_0.png') IO.imwrite(out, im)
def render_animation(seq, sub, dopoly): import pynutmeg import time import os import RayCloud fig = pynutmeg.figure('cube', 'figs/imshow.qml') W, H = 1920, 1080 im = empty((H, W, 3), np.uint8) cam = Geom.cam_params(29.97, W, H, 35) # Blender defaults cam = cam.astype(np.float32) print("Loading data") cloud = RayCloud.load(os.path.join(seq, sub)) datapath = os.path.join(seq, 'occlusion_data.npz') data = np.load(datapath) mesh_path = os.path.join(seq, 'occlusion_mesh.npz') occl_mesh = load_mesh(mesh_path) # occl_mesh = Mesh() # occl_mesh.verts = data['verts'].astype(np.float32) edges = data['edges'].astype(np.uint32) ply_path = os.path.join(seq, 'model.ply') if os.path.exists(ply_path): obj_mesh = from_ply(ply_path) else: obj_mesh = Mesh() if dopoly: poly_data = os.path.join(seq, sub, 'poly_data.npz') polynpz = np.load(poly_data) poly_mesh = Mesh() poly_mesh.verts = polynpz['verts'].astype(np.float32) poly_mesh.edges = polynpz['edges'].astype(np.uint32) else: poly_mesh = None # pers_mesh_path = os.path.join(seq, 'persistent_mesh.npz') # pers_mesh = load_mesh(pers_mesh_path) campath = os.path.join(seq, 'animation.py') Rs, ts = IO.import_blender_cam(campath) # Grab frame info inds = data['inds'] frames = cloud.frames[inds] render_out = os.path.join(seq, 'animate') Util.try_mkdir(render_out) F = len(Rs) N = len(frames) print("Loaded", frames.max()) end_frame = 0 for f in range(0, F, 10): print("Frame:", f) # R = cloud.Rs[f] # t = cloud.ts[f] R = Rs[f].astype(np.float32) t = ts[f].astype(np.float32) while end_frame < N and frames[end_frame] < f: end_frame += 1 occl_mesh.edges = edges[:end_frame] im[:] = 255 if len(occl_mesh.edges) > 0: t0 = time.time() render_frame(im, obj_mesh, occl_mesh, None, R, t, cam) print("Render time: {} ms".format( int((time.time() - t0)*1000) )) # time.sleep(0.005) fig.set('ax.im', binary=im) out = os.path.join(render_out, 'frame_{:05d}.png'.format(f)) IO.imwrite(out, im)
def test_render_seq(seq, sub, dopoly): import pynutmeg import time import os import RayCloud fig = pynutmeg.figure('cube', 'figs/imshow.qml') W, H = 1920, 1080 im = empty((H, W, 3), np.uint8) cam = Geom.cam_params(29.97, W, H, 35) # Blender defaults cam = cam.astype(np.float32) print("Loading data") cloud = RayCloud.load(os.path.join(seq, sub)) mesh_path = os.path.join(seq, 'occlusion_mesh.npz') occl_mesh = load_mesh(mesh_path) ply_path = os.path.join(seq, 'model.ply') if os.path.exists(ply_path): obj_mesh = from_ply(ply_path) else: obj_mesh = Mesh() if dopoly: poly_data = os.path.join(seq, sub, 'poly_data.npz') polynpz = np.load(poly_data) poly_mesh = Mesh() poly_mesh.verts = polynpz['verts'].astype(np.float32) poly_mesh.edges = polynpz['edges'].astype(np.uint32) else: poly_mesh = None pers_mesh_path = os.path.join(seq, 'persistent_mesh.npz') pers_mesh = load_mesh(pers_mesh_path) campath = os.path.join(seq, 'render.py') Rs, ts = IO.import_blender_cam(campath) render_out = os.path.join(seq, 'render') Util.try_mkdir(render_out) F = min(3, len(Rs)) print("Loaded") for f in range(F): print("Frame:", f) # R = cloud.Rs[f] # t = cloud.ts[f] R = Rs[f].astype(np.float32) t = ts[f].astype(np.float32) im[:] = 255 t0 = time.time() render_frame(im, obj_mesh, occl_mesh, None, R, t, cam) print("dt:", (time.time() - t0)*1000) # time.sleep(0.005) fig.set('ax.im', binary=im) out = os.path.join(render_out, 'frame_{}.png'.format(f)) IO.imwrite(out, im) im[:] = 255 t0 = time.time() render_frame(im, obj_mesh, pers_mesh, poly_mesh, R, t, cam, color=np.r_[255, 82, 82], poly_color=np.r_[0,0,0]) print("dt:", (time.time() - t0)*1000) fig.set('ax.im', binary=im) out = os.path.join(render_out, 'frame_pers_{}.png'.format(f)) IO.imwrite(out, im)