Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save yuki-inaho/9ae67248e9c6c2ebe632cf7fb2da4d35 to your computer and use it in GitHub Desktop.

Select an option

Save yuki-inaho/9ae67248e9c6c2ebe632cf7fb2da4d35 to your computer and use it in GitHub Desktop.
Open3D Point Cloud 3D Visualization with Rotating Camera
import open3d as o3d
import numpy as np
import time
# 点群を生成
pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(np.random.rand(1000, 3))
# ビジュアライザーの設定
vis = o3d.visualization.Visualizer()
vis.create_window()
vis.add_geometry(pcd)
# レンダリングオプションの設定
opt = vis.get_render_option()
opt.background_color = np.asarray([0, 0, 0]) # 背景を黒に設定
# カメラパラメータの設定
ctr = vis.get_view_control()
ctr.set_zoom(0.8)
# 点群の中心を取得
center = pcd.get_center()
# カメラの回転
for _ in range(36): # 10度ずつ36回回転(360度)
# カメラの位置を計算
radius = 2.0
theta = np.radians(_ * 10)
eye = center + np.array([np.sin(theta) * radius, 0, np.cos(theta) * radius])
# カメラの視点を更新
ctr.set_lookat(center)
ctr.set_front(center - eye)
ctr.set_up([0, 1, 0])
# 描画を更新
vis.update_geometry(pcd)
vis.poll_events()
vis.update_renderer()
time.sleep(0.1) # 回転速度の調整
# ビジュアライザーを閉じる
vis.destroy_window()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment