isl-org / isl-org/Open3D

I get the weird point cloud colors using Open3DScene

Open
#6,381 2 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
C++
Stars
14k
Forks
2.6k
Avg merge
5d 18h
Merged PRs (30d)
6

Description

### Checklist

- [X] I have searched for [similar issues](https://github.com/isl-org/Open3D/issues).
- [X] For Python issues, I have tested with the [latest development wheel](http://www.open3d.org/docs/latest/getting_started.html#development-version-pip).
- [X] I have checked the [release documentation](http://www.open3d.org/docs/release/) and the [latest documentation](http://www.open3d.org/docs/latest/) (for `master` branch).

### My Question

Hi, I have a colored point cloud, and I use the "open3d.visualization.visualizer" can get the good result.
However, I want to use the customized lighting for the point cloud, so I search that it can't use the visualizer to finish.
So, I try to use the "Open3DScene" to customize the lighting, and the result is very weird. I have tried to use different light intensity, light direction and object material parameters, it does not work ,too.
Or, is there other method to setup the lighting in open3d?
Can anyone help please, thanks a lot!!

This is code and result of "Open3DScene":
```
class Application:
def __init__(self):
app = gui.Application.instance
app.initialize()

window = app.create_window("test", 1024, 1024)
self.scene_widget = gui.SceneWidget()

self.scene_widget.scene = rendering.Open3DScene(window.renderer)
self.low_level()
window.add_child(self.scene_widget)

def low_level(self):
points = self.load_pontsRGB("point_cloud_path", "rgb_path")
mat = rendering.MaterialRecord()
mat.shader = "defaultLit" # defaultUnlit, defaultLit
mat.point_size = 5
mat.base_metallic = 0.0
mat.base_roughness = 0.8
mat.base_reflectance = 0.5
mat.base_clearcoat = 0.2
mat.base_clearcoat_roughness = 0.6
mat.base_anisotropy = 0.0

# mat.sRGB_color = True

self.scene_widget.scene.add_geometry("Points", points, mat, False)
self.scene_widget.scene.scene.enable_indirect_light(True)
self.scene_widget.scene.scene.enable_sun_light(False)
self.scene_widget.scene.set_background([0.0, 0.0, 0.0, 1.0])
self.scene_widget.scene.scene.remove_light('light')
# self.scene_widget.scene.scene.add_point_light('light', [1, 1, 1], np.array([0.0, 0.0, -1.5]), 1e6, 30, False)
self.scene_widget.scene.scene.add_directional_light('light', [0.5, 0.5, 0.5], np.array([0.0, 0.0, -1.5]), 4e5, True)
bbox = self.scene_widget.scene.bounding_box
self.scene_widget.setup_camera(20.0, bbox, bbox.get_center())

def load_pontsRGB(self, points_path, image_path):
unorg_pc, nonzero_idx = getPointCloud(points_path)
rgb_image = o3d.io.read_image(image_path)
img = np.array(rgb_image).reshape(-1,3)[nonzero_idx] / 255.0
pcd = o3d.geometry.PointCloud()
points_file = np.asarray(unorg_pc).reshape(-1,3)
colors_file = np.asarray(img).reshape(-1,3)
pcd.points = o3d.utility.Vector3dVector(points_file)
pcd.colors = o3d.utility.Vector3dVector(colors_file)
pcd.estimate_normals()
R = pcd.get_rotation_matrix_from_xyz((0, np.pi, np.pi))
pcd.rotate(R, center=(0, 0, 0))
return pcd

def run(self):
gui.Application.instance.run()

if __name__ == "__main__":
app = Application()
app.run()
```

![image](https://github.com/isl-org/Open3D/assets/43268022/f40655cc-d0f7-4daa-8614-35c37f7b50f7)

And this is code and result of visualizer:
```
class LightingImageFactory():
def __init__(self):
self.vis = o3d.visualization.Visualizer()
self.vis.create_window(width=500, height=500)

render_options = self.vis.get_render_option()
render_options.background_color = (0, 0, 0)
render_options.light_on = True

# render_options.scene.add_directional_light('light',[0.1,0.1,0.1], np.array([0, 0, 1.0]),5e5,True)

def load_data(self, points_path, image_path):
unorg_pc, nonzero_idx = getPointCloud(points_path)
rgb_image = Image.open(image_path).convert('RGB')
img = np.array(rgb_image).reshape(-1,3)[nonzero_idx] / 255.0
pcd = o3d.geometry.PointCloud()
points_file = np.asarray(unorg_pc).reshape(-1,3)
colors_file = np.asarray(img).reshape(-1,3)
pcd.points = o3d.utility.Vector3dVector(points_file)
pcd.colors = o3d.utility.Vector3dVector(colors_file)

pcd.estimate_normals()
R = pcd.get_rotation_matrix_from_xyz((0, np.pi, np.pi))
pcd.rotate(R, center=(0, 0, 0))
self.vis.add_geometry(pcd)
return pcd

def add_lighting(self, light_name, light_position, light_direction, light_intensity):
o3d.visualization.rendering.Scene.add_point_light('light',[1,1,1],np.array([-1,-1,0]),30,30,True)

def capture_image(self, save_path):
self.vis.capture_screen_image(save_path)

def run(self):
self.vis.poll_events()
self.vis.update_renderer()
self.vis.run()
self.capture_image(save_path)
self.vis.destroy_window()
```
![image](https://github.com/isl-org/Open3D/assets/43268022/a98b5b70-231d-4681-b644-f3c3be8f80c6)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.