0
$\begingroup$

Rosanswers logo

Hi, This may be trivial, but I have problems understanding how to parse data which comes as sensor_msgs::Image. I used the package openni_camera to get raw frames (camera/depth/image_raw). It says that it contains uint16 depths in mm. I am getting all values between 0 to 255, how do I get uint16?

As I understand, the data field is uint8[] data as shown here http://ros.org/doc/api/sensor_msgs/html/msg/Image.html. The same applies for camera/depth/points which is Pointcloud2 sending Float32. Again how is this represented in a uint8?

Thanks


Originally posted by aswin on ROS Answers with karma: 528 on 2013-06-20

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Ok one way to solve this is using cv_bridge. It uses 16UC1 encoding.

void dataCallback(const sensor_msgs::ImagePtr & msg) {

vector<unsigned short> depth;
cv_bridge::CvImagePtr cv_depth = cv_bridge::toCvCopy(msg,sensor_msgs::image_encodings::TYPE_16UC1);

for(int i=0; i<cv_depth->image.rows; i++) {
  for(int j=0; j<cv_depth->image.cols; j++) {
    unsigned short dd = *(cv_depth->image.ptr<unsigned short>(i,j));
    depth.push_back(dd);
  }
}

}

Cheers


Originally posted by aswin with karma: 528 on 2013-06-20

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.