Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. #include <ros/ros.h>
  2. #include <image_transport/image_transport.h>
  3. #include <cv_bridge/cv_bridge.h>
  4. #include <sensor_msgs/image_encodings.h>
  5. #include <opencv2/imgproc/imgproc.hpp>
  6.  
  7. class ImageConverter {
  8. public:
  9. ros::NodeHandle nh_;
  10. image_transport::ImageTransport it_;
  11. image_transport::Subscriber image_sub_;
  12. image_transport::Publisher image_pub_;
  13.  
  14. public:
  15. ImageConverter() :
  16. it_(nh_) {
  17. // Subscrive to input video feed and publish output video feed
  18. image_sub_ = it_.subscribe( "/camera/image_raw", 1, &ImageConverter::imageCb, this );
  19. image_pub_ = it_.advertise( "/image_converter/output_video", 1 );
  20. }
  21.  
  22. ~ImageConverter() {
  23. }
  24.  
  25. void imageCb( const sensor_msgs::ImageConstPtr& msg ) {
  26. cv_bridge::CvImagePtr cv_ptr;
  27. try {
  28. cv_ptr = cv_bridge::toCvCopy( msg, sensor_msgs::image_encodings::BGR8 );
  29. } catch ( cv_bridge::Exception& e ) {
  30. ROS_ERROR(" cv_bridge exception: %s", e.what() );
  31. return;
  32. }
  33.  
  34. // Draw an example circle on the video stream
  35. if( ( cv_ptr->image.rows > 60 ) && ( cv_ptr->image.cols > 60 ) )
  36. cv::circle( cv_ptr->image, cv::Point( 50, 50 ), 10, CV_RGB( 255, 0, 0 ) );
  37.  
  38. // Output modified video stream
  39. image_pub_.publish( cv_ptr->toImageMsg() );
  40. }
  41. };
  42.  
  43. int main( int argc, char** argv ) {
  44. ros::init( argc, argv, "image_converter" );
  45. ImageConverter ic;
  46. ros::spin();
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement