Displaying Kinect images using Python, ROS, and cv_bridge

The first section of the Python code is given in the following code fragment. It mainly involves importing rospy, sys, cv2, sensor_msgs, cv_bridge, and the numpy module. The sensor_msgs dependency imports the ROS data type of both image and camera information type. The cv_bridge module imports the CvBridge class for converting the ROS image data type to the OpenCV data type and vice versa:

import rospyimport sysimport cv2from sensor_msgs.msg import Image, CameraInfofrom cv_bridge import CvBridge, CvBridgeErrorfrom std_msgs.msg import Stringimport numpy as np

The following section of code is a class definition in Python that we will use to demonstrate CvBridge functions. The class is ...

Get Learning Robotics using Python - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.