Removing Background from point cloud with D435
I have a point cloud which is exported from export_to_ply but i need to remove the background by using the clipping distance as shown in this link
and then i need to use this clipped frame to get the point cloud for it but it giving me this error:
points = pc.calculate(bg_removed_depth)
TypeError: calculate(): incompatible function arguments. The following argument types are supported:
1. (self: pyrealsense2.pyrealsense2.pointcloud, depth: pyrealsense2.pyrealsense2.frame) -> pyrealsense2.pyrealsense2.points
i don't know how to convert the numpy array to a frame again.
Here is my code:
pc=rs.pointcloud()
points=rs.points()
aligned_frames=align.process(frames)
aligned_depth_frame=aligned_frames.get_depth_frame()
color_frame=aligned_frames.get_color_frame()
depth_image=np.asanyarray(aligned_depth_frame.get_data())
color_image=np.asanyarray(color_frame.get_data())
# Remove background - Set pixels further than clipping_distance to grey
grey_color=153
bg_removed_depth=np.where((depth_image>clipping_distance)|(depth_image<=0),grey_color,depth_image)
points=pc.calculate(bg_removed_depth)
pc.map_to(color_frame)
colorizer=rs.colorizer()
colorized_depth=cv2.applyColorMap(cv2.convertScaleAbs(bg_removed_depth,alpha=0.03),cv2.COLORMAP_JET)
cv2.imshow("image",colorized_depth)
key=cv2.waitKey(1)
if key==ord("s"):
print("Saving pcd_{}.ply".format(counter))
points.export_to_ply("/home/jomana/masters_ws/src/Studying/Thesis/robot_version/img/point_cloud/pcd_{}.ply".format(counter),color_frame)
counter+=1
elif keyin(27,ord("q")):
break
-
Hi Jomanaashraf8 Conversion of a numpy array back to the SDK rs2::frame format is something that has been attempted in the past by RealSense Python users but as far as I am aware it remains an unsolved problem.
https://github.com/IntelRealSense/librealsense/issues/2551
It is not recommendable to use align_to (the align-depth2color.py alignment method) and pc.calculate / pc.map_to in the same script, as map_to is mapping depth and RGB together and so you are aligning twice, which can lead to inaccuracy in the aligned image.
You could instead only use the pc.calculate / pc.map_to method of alignment and apply a Threshold filter to remove the background by setting a maximum distance for the depth values that are permitted to be rendered on the image.
Please sign in to leave a comment.
Comments
1 comment