Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return np array of a big image
'''
cam = PerspectiveCamera(yfov=(YFOV))
cam_pose = CAM_POSE
point_l = PointLight(color=np.ones(3), intensity=POINT_LIGHT_INTENSITY)
scene = Scene(bg_color=np.array([1,1,1,0]))
# cam and light
_ = scene.add(cam, pose=cam_pose)
_ = scene.add(point_l, pose=cam_pose)
input_ply_filenames = get_all_filnames(results_dir, nb)
r = OffscreenRenderer(viewport_width=640*2, viewport_height=480*2, point_size=POINT_SIZE)
pc_pose = PC_POSE
images = []
for _, input_pf in enumerate(input_ply_filenames):
input_pc = read_ply_xyz(input_pf)
colors = np.array(pts_colors)
colors = np.tile(colors, (input_pc.shape[0], 1))
input_pc_node = add_point_cloud_mesh_to_scene(input_pc, scene, pc_pose, colors)
renderred_color, _ = r.render(scene)
scene.remove_node(input_pc_node)
assert args.num_scenes_per_file <= total_scenes_to_render
# Initialize colors
color_candidates = []
for n in range(args.num_colors):
hue = n / args.num_colors
saturation = 1
lightness = 1
red, green, blue = colorsys.hsv_to_rgb(hue, saturation, lightness)
color_candidates.append((red, green, blue))
scene, cube_nodes = build_scene(args.num_cubes, color_candidates)
camera = OrthographicCamera(xmag=0.9, ymag=0.9)
camera_node = Node(camera=camera)
scene.add_node(camera_node)
renderer = OffscreenRenderer(
viewport_width=args.image_size, viewport_height=args.image_size)
archiver = Archiver(
directory=args.output_directory,
num_scenes_per_file=args.num_scenes_per_file,
image_size=(args.image_size, args.image_size),
num_observations_per_scene=args.num_observations_per_scene,
initial_file_number=initial_file_number)
for scene_index in tqdm(range(total_scenes_to_render)):
camera_distance = 2
scene_data = SceneData((args.image_size, args.image_size),
args.num_observations_per_scene)
for observation_index in range(args.num_observations_per_scene):
# Generate random point on a sphere
initial_file_number = number + 1
total_scenes_to_render = args.total_scenes - args.num_scenes_per_file * (
initial_file_number - args.initial_file_number)
assert args.num_scenes_per_file <= total_scenes_to_render
# Colors
colors = []
for n in range(args.num_colors):
hue = n / args.num_colors
saturation = 1
lightness = 1
red, green, blue = colorsys.hsv_to_rgb(hue, saturation, lightness)
colors.append(np.array((red, green, blue, 1)))
renderer = OffscreenRenderer(
viewport_width=args.image_size, viewport_height=args.image_size)
archiver = Archiver(
directory=args.output_directory,
num_scenes_per_file=args.num_scenes_per_file,
image_size=(args.image_size, args.image_size),
num_observations_per_scene=args.num_observations_per_scene,
initial_file_number=initial_file_number)
for scene_index in tqdm(range(total_scenes_to_render)):
scene = build_scene(
floor_textures,
wall_textures,
fix_light_position=args.fix_light_position)
place_objects(
scene,
# Using the viewer with a default camera
#==============================================================================
v = Viewer(scene, shadows=True)
#==============================================================================
# Using the viewer with a pre-specified camera
#==============================================================================
cam_node = scene.add(cam, pose=cam_pose)
v = Viewer(scene, central_node=drill_node)
#==============================================================================
# Rendering offscreen from that camera
#==============================================================================
r = OffscreenRenderer(viewport_width=640*2, viewport_height=480*2)
color, depth = r.render(scene)
r.delete()
import matplotlib.pyplot as plt
plt.figure()
plt.imshow(color)
plt.show()
pass
# Initialize colors
color_candidates = []
for n in range(args.num_colors):
hue = n / args.num_colors
saturation = 1
lightness = 1
red, green, blue = colorsys.hsv_to_rgb(hue, saturation, lightness)
color_candidates.append((red, green, blue))
scene, cube_nodes = build_scene(color_candidates)
camera = OrthographicCamera(xmag=0.9, ymag=0.9)
camera_node = Node(camera=camera)
scene.add_node(camera_node)
renderer = OffscreenRenderer(
viewport_width=args.image_size, viewport_height=args.image_size)
camera_distance = 2
archiver = Archiver(
directory=args.output_directory,
total_scenes=args.total_scenes,
num_scenes_per_file=min(args.num_scenes_per_file, args.total_scenes),
image_size=(args.image_size, args.image_size),
num_observations_per_scene=args.num_observations_per_scene,
initial_file_number=args.initial_file_number)
for scene_index in tqdm(range(args.total_scenes)):
scene_data = SceneData((args.image_size, args.image_size),
args.num_observations_per_scene)
initial_file_number = number + 1
total_scenes_to_render = args.total_scenes - args.num_scenes_per_file * (
initial_file_number - args.initial_file_number)
assert args.num_scenes_per_file <= total_scenes_to_render
# Colors
colors = []
for n in range(args.num_colors):
hue = n / args.num_colors
saturation = 1
lightness = 1
red, green, blue = colorsys.hsv_to_rgb(hue, saturation, lightness)
colors.append(np.array((red, green, blue, 1)))
renderer = OffscreenRenderer(
viewport_width=args.image_size, viewport_height=args.image_size)
archiver = Archiver(
directory=args.output_directory,
num_scenes_per_file=args.num_scenes_per_file,
image_size=(args.image_size, args.image_size),
num_observations_per_scene=args.num_observations_per_scene,
initial_file_number=initial_file_number)
for scene_index in tqdm(range(total_scenes_to_render)):
scene = build_scene(
floor_textures,
wall_textures,
fix_light_position=args.fix_light_position)
place_objects(
scene,
def main():
# Load MNIST images
mnist_images = load_mnist_images()
renderer = OffscreenRenderer(
viewport_width=args.image_size, viewport_height=args.image_size)
plt.tight_layout()
fig = plt.figure(figsize=(6, 3))
axis_perspective = fig.add_subplot(1, 2, 1)
axis_orthogonal = fig.add_subplot(1, 2, 2)
ims = []
scene = build_scene(
floor_textures,
wall_textures,
fix_light_position=args.fix_light_position)
place_dice(
scene,
mnist_images,
discrete_position=args.discrete_position,
def render_obj_pyrender(self,mesh,rot,tra):
pred_pose=np.eye(4)
pred_pose[:3,:3]=rot.reshape(3,3)
if(tra[2]>100):tra=tra/1000
pred_pose[:3,3]=tra
scene=pyrender.Scene()
camera = pyrender.IntrinsicsCamera(self.camK[0,0],self.camK[1,1],
self.camK[0,2],self.camK[1,2])
camera_pose = np.array([[1.0, 0, 0.0, 0],
[0.0, -1.0, 0.0, 0],
[0.0, 0.0, -1, 0],
[0.0, 0.0, 0.0, 1.0]])
scene.add(camera,pose=camera_pose)
scene.add(mesh,pose=pred_pose)
r = pyrender.OffscreenRenderer(self.im_width, self.im_height)
color,depth = r.render(scene)
return color,depth
camera = pyrender.camera.OrthographicCamera(xmag=0.001*0.5*width, ymag=0.001*0.5*height, znear=0.01, zfar=10)
camera_pose = np.eye(4)
camera_pose[:3, 3] = np.array([0.001*0.5*width, 0.001*0.5*height, 1.0])
scene.add(camera, pose=camera_pose)
light = pyrender.PointLight(color=[1.0, 1.0, 1.0], intensity=1.0)
light_pose = np.eye(4)
light_pose[:3, 3] = np.array([1.0, 1.0, 1.0])
scene.add(light, pose=light_pose.copy())
light_pose[:3, 3] = np.array([0.0, 1.0, 1.0])
scene.add(light, pose=light_pose.copy())
try:
r = pyrender.OffscreenRenderer(viewport_width=width, viewport_height=height)
color, _ = r.render(scene)
except:
print('Rendering failed')
color = np.zeros((height, width, 3))
return color[..., ::-1].copy()