-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(point_cloud): Adds point cloud example an
- Loading branch information
1 parent
61f7092
commit 1aa9a0b
Showing
8 changed files
with
193 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Point clouds | ||
|
||
<p align="center"> | ||
<img src="../../../images/point_clouds_0.jpg" alt="Front readme image" width=375> | ||
<img src="../../../images/point_clouds_1.jpg" alt="Front readme image" width=375> | ||
</p> | ||
|
||
In this example we demonstrate how to compute a depth map with raytracing and how to unproject it into a point cloud. | ||
The point cloud is computed from the view of the second camera pose (right image) and is visualized using red dots. | ||
|
||
## Usage | ||
|
||
Execute in the Blender-Pipeline main directory: | ||
|
||
``` | ||
blenderproc run examples/advanced/point_clouds/main.py examples/resources/camera_positions examples/resources/scene.obj examples/basics/basic/output | ||
``` | ||
|
||
* `examples/resources/camera_positions`: text file with parameters of camera positions. | ||
* `examples/resources/scene.obj`: path to the object file with the basic scene. | ||
* `examples/basics/basic/output`: path to the output directory. | ||
|
||
## Visualization | ||
|
||
Visualize the generated data: | ||
|
||
``` | ||
blenderproc vis hdf5 examples/advanced/point_clouds/output/0.hdf5 | ||
``` | ||
|
||
## Implementation | ||
|
||
First we are computing a depth image via raytracing using the camera pose set to keyframe #1. | ||
|
||
``` | ||
depth = bproc.camera.depth_via_raytracing(bvh_tree, 1) | ||
``` | ||
|
||
Alternatively, one could also use the renderer to render a depth image: | ||
|
||
``` | ||
data = bproc.renderer.render() | ||
depth = data["depth"][1] | ||
``` | ||
|
||
We now unproject the depth image again, resulting in a point cloud. | ||
The point cloud contains one point per pixel. | ||
|
||
``` | ||
points = bproc.camera.pointcloud_from_depth(depth, 1) | ||
points = points.reshape(-1, 3) | ||
``` | ||
|
||
To visualize the point cloud, we create a mesh with vertices set from the point cloud. | ||
To be able to see the points in the final rendering, we add geometry nodes which add a sphere mesh to each point. | ||
|
||
``` | ||
point_cloud = bproc.object.create_from_point_cloud(points, "point_cloud", add_geometry_nodes_visualization=True) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import blenderproc as bproc | ||
import argparse | ||
import numpy as np | ||
|
||
from blenderproc.python.utility.Utility import Utility | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument('camera', nargs='?', default="examples/resources/camera_positions", help="Path to the camera file") | ||
parser.add_argument('scene', nargs='?', default="examples/resources/scene.obj", help="Path to the scene.blend file") | ||
parser.add_argument('output_dir', nargs='?', default="examples/advanced/point_clouds/output", help="Path to where the final files will be saved ") | ||
args = parser.parse_args() | ||
|
||
bproc.init() | ||
|
||
# load the objects into the scene | ||
objs = bproc.loader.load_obj(args.scene) | ||
|
||
# define a light and set its location and energy level | ||
light = bproc.types.Light() | ||
light.set_type("POINT") | ||
light.set_location([5, -5, 5]) | ||
light.set_energy(1000) | ||
|
||
# define the camera resolution | ||
bproc.camera.set_resolution(128, 128) | ||
bvh_tree = bproc.object.create_bvh_tree_multi_objects(objs) | ||
# read the camera positions file and convert into homogeneous camera-world transformation | ||
with open(args.camera, "r") as f: | ||
for line in f.readlines(): | ||
line = [float(x) for x in line.split()] | ||
position, euler_rotation = line[:3], line[3:6] | ||
matrix_world = bproc.math.build_transformation_mat(position, euler_rotation) | ||
bproc.camera.add_camera_pose(matrix_world) | ||
|
||
# Compute a depth image from the view of the second camera pose | ||
depth = bproc.camera.depth_via_raytracing(bvh_tree, 1) | ||
|
||
# Project the depth again to get a point cloud | ||
points = bproc.camera.pointcloud_from_depth(depth, 1) | ||
points = points.reshape(-1, 3) | ||
|
||
# Visualize the points cloud as a mesh | ||
point_cloud = bproc.object.create_from_point_cloud(points, "point_cloud", add_geometry_nodes_visualization=True) | ||
|
||
# render the whole pipeline | ||
bproc.camera.set_resolution(512, 512) | ||
data = bproc.renderer.render() | ||
|
||
# write the data to a .hdf5 container | ||
bproc.writer.write_hdf5(args.output_dir, data) | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters