RealSense D435 Camera - penn-figueroa-lab/lab_wiki GitHub Wiki

  1. Install ROS Noetic (if not already using it).
    https://github.com/IntelRealSense/realsense-ros/tree/ros1-legacy
  2. Install Realsense Ros Wrapper (method 1 recommended)
    https://github.com/IntelRealSense/realsense-ros/tree/ros1-legacy
  3. Setup the basic ROS environment
    I used catkin environment and created the package using it.
    http://wiki.ros.org/catkin
  4. Install ros_numpy library (bash)
    sudo apt install ros-noetic-ros-numpy
  5. Start a Realsense camera (bash)
    roslaunch realsense2_camera rs_camera.launch align_depth:=true filters:=pointcloud
  6. Run the Python code (bash)
    rosrun $your_package$ camera.py
#!/usr/bin/env python
# license removed for brevity
import rospy
import numpy as np
import ros_numpy
import rosbag
import sensor_msgs
​
def callback(pointcloud_msg):  
  pointcloud_np = ros_numpy.point_cloud2.pointcloud2_to_xyz_array(pointcloud_msg, remove_nans=True)
  print("Point cloud shape: "+str(pointcloud_np.shape), end="\r")
    
def receive_message():
  rospy.init_node('pointcloud_sub_py', anonymous=True)
  rospy.Subscriber('/camera/depth/color/points', sensor_msgs.msg._PointCloud2.PointCloud2, callback)
  rospy.spin()
  
if __name__ == '__main__':
  receive_message()
  print()

Contributor: Ho Jin Choi