ROS image transport is very similar to ROS Publishers and Subscribers and it is used to publish/subscribe the images along with the camera information. We can publish the image data using ros::Publishers, but image transport is a more efficient way of sending the image data.
The image transport APIs are provided by the image_transport package. Using these APIs, we can transport an image in different compression formats; for example, we can transport it as an uncompressed image, JPEG/PNG compression, or Theora compression in separate Topics. We can also add different transport formats by adding plugins. By default, we can see the compressed and Theora transports.
image_transport::ImageTransport it_;
In the following line, we are creating an instance of the ImageTransport class:
image_transport::Subscriber image_sub_; image_transport::Publisher image_pub_;
After that, we declare the Subscriber and Publisher objects for subscribing and publishing the images using the image_transport object:
image_sub_ = it_.subscribe("/usb_cam/image_raw", 1, &ImageConverter::imageCb, this); image_pub_ = it_.advertise("/edge_detector/processed_image", 1);
The following is how we subscribe and publish an image:
cv::namedWindow(OPENCV_WINDOW); } ~Edge_Detector() { cv::destroyWindow(OPENCV_WINDOW); }
This is how we subscribe and publish an image.cv::namedWindow() is an OpenCV function to create a GUI for displaying an image. The argument inside this function is the window name. Inside the class destructor, we are destroying the named window.