Ask Your Question

How to work with kinect frames in RGB color format using cvbridge

asked 2013-11-07 14:26:13 -0500

SM gravatar image

updated 2016-10-24 08:35:38 -0500

ngrennan gravatar image

I am trying to process color kinect frames following the tutorial from the link working with cv bridge. I have a training image juice_color.png which I can visualize as RGB. I specified the encoding as cv_img.encoding = "rgb8";

Going by the same logic, I used rgb8 for the incoming kinect frames, but the display window imshow( WINDOW2, cv_ptr_frames->image ); shows the kinect frames in gray scale. How do I work with RGB kinect frames ? How to prevent the color format change to gray scale? Thanking you.

static const std::string OPENCV_WINDOW1 = "Good Matches";
static const std::string WINDOW1 = "Training Image ";
static const std::string WINDOW2 = "Test Frames ";

class ImageConverter
  ros::NodeHandle nh_;
  image_transport::ImageTransport it_;
  image_transport::Subscriber image_sub_;
  image_transport::Publisher image_pub_;

    : it_(nh_)
    // Subscrive to input video feed and publish output video feed
    image_sub_ = it_.subscribe("/camera/rgb/image_rect", 1, 
      &ImageConverter::imageCb, this);
    image_pub_ = it_.advertise("/image_converter/output_video", 1);





  void imageCb(const sensor_msgs::ImageConstPtr& msg)

 cv_bridge::CvImage cv_img;   // training image
 cv_bridge::CvImage cv_img_proc;  

 cv_bridge::CvImagePtr cv_ptr_frames; // kinect frames

 cv::Mat object = imread( "juice_color.png" );

   imshow( WINDOW1, object );  //Displayed in RGB color

 cv_img.header.stamp = ros::Time::now();
 cv_img.encoding = "rgb8";
 cv_img.encoding = sensor_msgs::image_encodings::RGB8;
 cv_img.image = object;

  sensor_msgs::Image im;

     cv_ptr_frames = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::RGB8);
    catch (cv_bridge::Exception& e)
     ROS_ERROR("cv_bridge exception: %s", e.what());

    imshow( WINDOW2, cv_ptr_frames->image   );
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-01-17 03:04:43 -0500

Wolf gravatar image

Typically OpenCV highgui functions (imread, imwrite, imshow etc) use color model BGR8, so probably your image is in BGR8 not RGB8. Pushing it through cv_bridge with wrong color model may cause trouble, so try BGR8.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2013-11-07 14:26:13 -0500

Seen: 1,442 times

Last updated: Jan 17 '14