ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

Looking at the openni_camera documentation on the ROS wiki, you can see that the openni_node broadcasts several topics.

I think for the data that you are looking for, the topics of interest will be the depth/image_raw messages, or the depth_registered/image_raw if you have the OpenNI registration turned on.

The */image_raw messages are in the sensor_msgs/Image message format, which stores the data in a byte array, that can then be reassembled in the subscriber. This is accomplished using cv_bridge.

cv_bridge allows you to write code like this for your callback:

void imageCb(const sensor_msgs::ImageConstPtr& msg)
{
  cv_bridge::CvImagePtr cv_ptr;
  try
  {
    cv_ptr = cv_bridge::toCvCopy(msg, enc::TYPE_16UC1);
  }
  catch (cv_bridge::Exception& e)
  {
    ROS_ERROR("cv_bridge exception: %s", e.what());
    return;
  }
  cv::imshow(WINDOW, cv_ptr->image);
  image_pub_.publish(cv_ptr->toImageMsg());
}

cv_ptr->image will contain an OpenCV cv::Mat, in this case containing unsigned integer values (unit16) in mm.

Looking at the openni_camera documentation on the ROS wiki, you can see that the openni_node broadcasts several topics.

I think for the data that you are looking for, the topics of interest will be the depth/image_raw messages, or the depth_registered/image_raw if you have the OpenNI registration turned on.

The */image_raw messages are in the sensor_msgs/Image message format, which stores the data in a byte array, that can then be reassembled in the subscriber. This is accomplished using cv_bridge.

cv_bridge allows you to write code like this for your callback:

void imageCb(const sensor_msgs::ImageConstPtr& msg)
{
  cv_bridge::CvImagePtr cv_ptr;
  try
  {
    cv_ptr = cv_bridge::toCvCopy(msg, enc::TYPE_16UC1);
  }
  catch (cv_bridge::Exception& e)
  {
    ROS_ERROR("cv_bridge exception: %s", e.what());
    return;
  }
  cv::imshow(WINDOW, cv_ptr->image);
  image_pub_.publish(cv_ptr->toImageMsg());
}

cv_ptr->image will contain an OpenCV cv::Mat, in this case containing unsigned integer values (unit16) in mm.

(uint16), which represent the depth in millimeters for that pixel.

Looking at the openni_camera documentation on the ROS wiki, you can see that the openni_node broadcasts several topics.

I think for the data that you are looking for, the topics of interest will be the depth/image_raw messages, or the depth_registered/image_raw if you have the OpenNI registration turned on.

The */image_raw messages are in the sensor_msgs/Image message format, which stores the data in a byte array, that can then be reassembled in the subscriber. This is accomplished using cv_bridge.

cv_bridge allows you to write code like this for your callback:

void imageCb(const sensor_msgs::ImageConstPtr& msg)
{
  cv_bridge::CvImagePtr cv_ptr;
  try
  {
    cv_ptr = cv_bridge::toCvCopy(msg, enc::TYPE_16UC1);
enc::TYPE_32FC1);
  }
  catch (cv_bridge::Exception& e)
  {
    ROS_ERROR("cv_bridge exception: %s", e.what());
    return;
  }
  cv::imshow(WINDOW, cv_ptr->image);
  image_pub_.publish(cv_ptr->toImageMsg());
}

cv_ptr->image will contain an OpenCV cv::Mat, in this case containing unsigned integer values (uint16), floating point values, which represent the depth in millimeters for that pixel.