import cv2 from sensor_msgs.msg import Image from cv_bridge import CvBridge def callback(image_message): bridge = CvBridge() cv_image = bridge.imgmsg_to_cv2(image_message, "bgr8") cv2.imshow("Image Window", cv_image) cv2.waitKey(1)
import cv2 from sensor_msgs.msg import Image from cv_bridge import CvBridge def callback(images_message): bridge = CvBridge() for image_message in images_message: cv_image = bridge.imgmsg_to_cv2(image_message, "bgr8") cv2.imshow("Image Window", cv_image) cv2.waitKey(1)In this example, multiple ROS image messages are converted to OpenCV images using imgmsg_to_cv2 function. The images are then displayed in a window using the imshow function from OpenCV. Both examples use the CvBridge package library to utilize the imgmsg_to_cv2 function to convert ROS image messages to OpenCV format.