srinath R
srinath R

Reputation: 19

How can we pick 3D points from point cloud data (from a .PCD file) using python?

I have a .pcd file that I need to visualize and pick points from the file.

I am using:

import numpy as np
from open3d import *    

def main():
    pcd = read_point_cloud("C:/Users/rsr5le/Desktop/m_data_2018_11_19__15_58_08.pcd") # Read the point cloud
    draw_geometries([pcd]) # Visualize the point cloud     


if __name__ == "__main__":
    main()

xyz is the point that I need to pick in the file.

Upvotes: 2

Views: 4872

Answers (2)

Ardiya
Ardiya

Reputation: 725

Please use open3d.VisualizerWithEditing with the code shown below. Remember to press Shift + Left click when the visualizer is running. If you pressed correctly, you should be able to see a sphere added into the visualizer

import open3d
a = open3d.read_point_cloud("a.pcd")
# Visualize cloud and edit
vis = open3d.VisualizerWithEditing()
vis.create_window()
vis.add_geometry(a)
vis.run()
# Picked point #84 (-0.00, 0.01, 0.01) to add in queue.
# Picked point #119 (0.00, 0.00, -0.00) to add in queue.
# Picked point #69 (-0.01, 0.02, 0.01) to add in queue.
vis.destroy_window()
print(vis.get_picked_points()) #[84, 119, 69]

enter image description here

Upvotes: 2

DrBwts
DrBwts

Reputation: 3657

You can put the points into a numpy array & search through them to find its index in the array of points,

point_to_find = np.array([2, 3, 4]) # this is your xyz
point_cloud_array = np.asarray(pcd.points)

try:
    print(np.where(np.all(point_cloud_array==point_to_find, axis=1))[0][0])
except:
    print("not in array")

Upvotes: 1

Related Questions