Foxy Image subscriber experiment pro.cpp
From wikidb
// Image Subscriber Demo - procedural version // // Based on Adding Video Capture in ROS 2 // https://www.stereolabs.com/docs/ros2/video/ // // Ed C. Epp #include <memory> #include "rclcpp/rclcpp.hpp" #include "sensor_msgs/msg/image.hpp" // Declare the node pointer rclcpp::Node::SharedPtr g_node = nullptr; // --------------------------------------------------------------------- // Create the image callback function void image_callback(const sensor_msgs::msg::Image::SharedPtr msg) { RCLCPP_INFO(g_node->get_logger(), "I See: " + msg->encoding); } // -------------------------------------------------------------------- // main int main(int argc, char* argv[]) { // Act on the parameters and other stuff rclcpp::init(argc, argv); // Create the ROS node g_node = rclcpp::Node::make_shared("Image_Subscriber_Pro_Test"); // Set the quality of service rclcpp::QoS video_qos(10); video_qos.keep_last(10); video_qos.best_effort(); video_qos.durability_volatile(); // Subscribe to image topics auto subscription_ = g_node->create_subscription<sensor_msgs::msg::Image>( "image", video_qos, image_callback); RCLCPP_INFO(g_node->get_logger(), "Image subscriber created"); // Start the node up rclcpp::spin(g_node); rclcpp::shutdown(); return 0; }