Nalyd1002

open3d

Apr 28th, 2023
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. import open3d as o3d
  2. import open3d.core as o3c
  3. import numpy as np
  4. import matplotlib.pyplot as plt
  5. import copy
  6. import os
  7. import sys
  8.  
  9. import pybullet as p
  10. import numpy as np
  11. import pybullet_data
  12. import time
  13.  
  14. # Initialize the physics simulation
  15. physicsClient = p.connect(p.GUI)
  16. p.setAdditionalSearchPath(pybullet_data.getDataPath())
  17.  
  18. # Load the objects into the simulation
  19. planeId = p.loadURDF("plane.urdf")
  20. #sphereId = p.loadURDF("sphere_small.urdf", [0, 1, 0])
  21. #cylinderId = p.loadURDF("sphere_small.urdf", [0.5, 1, 0])
  22. #robotId = p.loadURDF("r2d2.urdf", [0.5,0.5,0.5],useFixedBase=True)
  23.  
  24. while True:
  25. # Get the image from the camera
  26. camera_pos = [0, 1, 2]
  27. viewMatrix = p.computeViewMatrix(
  28. cameraEyePosition=camera_pos,
  29. cameraTargetPosition=[0, 1, 0],
  30. cameraUpVector=[0, 1, 0])
  31.  
  32. # Set the intrinsic parameters of the camera
  33. fov = 60
  34. aspect = 320.0 / 240.0
  35. near = 0.01
  36. far = 100
  37.  
  38. # Get the image from the camera
  39. width, height, rgbImg, depthImg, segImg = p.getCameraImage(width=320, height=240, viewMatrix=viewMatrix,
  40. projectionMatrix=p.computeProjectionMatrixFOV(fov,
  41. aspect,
  42. near, far))
  43. # Convert the depth image to a point cloud
  44. points = np.zeros((height * width, 3))
  45. for y in range(height):
  46. for x in range(width):
  47. depth = depthImg[y, x]
  48. if depth != 0:
  49. points[y * width + x, 0] = (x - 160) * depth / 160.0
  50. points[y * width + x, 1] = (y - 120) * depth / 120.0
  51. points[y * width + x, 2] = depth
  52. print(points)
  53.  
  54. print("Load a ply point cloud, print it, and render it")
  55. ply_point_cloud = o3d.data.PLYPointCloud()
  56. #pcd = o3d.t.io.read_point_cloud(ply_point_cloud.path)
  57. # Create a point cloud from python list.
  58. pcd = o3d.t.geometry.PointCloud(points)
  59. print(pcd, "\n")
  60.  
  61. """o3d.visualization.draw_geometries([pcd.to_legacy()],
  62. zoom=0.3412,
  63. front=[0.4257, -0.2125, -0.8795],
  64. lookat=[2.6172, 2.0475, 1.532],
  65. up=[-0.0694, -0.9768, 0.2024])"""
  66. #normals = pcd.point.normals
  67. print("Print first 5 normals of the downsampled point cloud.")
  68. #print(normals[:5], "\n")
  69. print("Convert normals tensor into numpy array.")
  70. #normals_np = normals.numpy()
  71. #print(normals_np[:5])
  72. print("finish")
  73.  
Advertisement
Add Comment
Please, Sign In to add comment