-
-
Save hello-fazil/bee106b7f22dd5a89f00ba43bddbe28a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import rclpy | |
from rclpy.node import Node | |
from sensor_msgs.msg import Image | |
from cv_bridge import CvBridge | |
import cv2 | |
class ImageSubscriber(Node): | |
def __init__(self): | |
super().__init__('image_subscriber') | |
self.declare_parameter('camera_topic','/navigation_camera/image_raw') | |
self.camera_topic = self.get_parameter('camera_topic').value | |
self.subscription = self.create_subscription( | |
Image, | |
self.camera_topic, | |
self.image_callback, | |
1) | |
self.cv_bridge = CvBridge() | |
def image_callback(self, msg): | |
try: | |
cv_image = self.cv_bridge.imgmsg_to_cv2(msg, "bgr8") | |
except Exception as e: | |
self.get_logger().error("Error converting ROS Image to OpenCV image: %s" % str(e)) | |
return | |
cv2.imshow("Image", cv_image) | |
cv2.waitKey(1) | |
def main(args=None): | |
rclpy.init(args=args) | |
image_subscriber = ImageSubscriber() | |
rclpy.spin(image_subscriber) | |
image_subscriber.destroy_node() | |
rclpy.shutdown() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To be used for testing the below PR
hello-robot/stretch_ros2#105