Skip to content

Commit 846237a

Browse files
authored
RSDK-857 - add pcd docs (#202)
1 parent 55372f9 commit 846237a

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/viam/components/camera/camera.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,20 @@ async def get_point_cloud(self, *, timeout: Optional[float] = None, **kwargs) ->
5252
should encode the bytes into the formatted suggested
5353
by the mimetype.
5454
55+
To deserialize the returned information into a numpy array, use the Open3D library.
56+
::
57+
58+
import numpy as np
59+
import open3d as o3d
60+
61+
data, _ = await camera.get_point_cloud()
62+
63+
# write the point cloud into a temporary file
64+
with open("/tmp/pointcloud_data.pcd", "wb") as f:
65+
f.write(data)
66+
pcd = o3d.io.read_point_cloud("/tmp/pointcloud_data.pcd")
67+
points = np.asarray(pcd.points)
68+
5569
Returns:
5670
bytes: The pointcloud data.
5771
str: The mimetype of the pointcloud (e.g. PCD).

src/viam/services/vision.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,20 @@ async def get_object_point_clouds(
341341
Returns a list of the 3D point cloud objects and associated metadata in the latest
342342
picture obtained from the specified 3D camera (using the specified segmenter).
343343
344+
To deserialize the returned information into a numpy array, use the Open3D library.
345+
::
346+
347+
import numpy as np
348+
import open3d as o3d
349+
350+
object_point_clouds = await vision.get_object_point_clouds(camera_name, segmenter_name)
351+
352+
# write the first object point cloud into a temporary file
353+
with open("/tmp/pointcloud_data.pcd", "wb") as f:
354+
f.write(object_point_clouds[0].point_cloud)
355+
pcd = o3d.io.read_point_cloud("/tmp/pointcloud_data.pcd")
356+
points = np.asarray(pcd.points)
357+
344358
Args:
345359
camera_name (str): The name of the camera
346360
segmenter_name (str): The name of the segmenter

0 commit comments

Comments
 (0)