Ask Your Question

How to parse sensor_msgs::Image data?

asked 2013-06-20 05:29:18 -0500

aswin gravatar image

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 The same applies for camera/depth/points which is Pointcloud2 sending Float32. Again how is this represented in a uint8?


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2013-06-20 16:41:30 -0500

aswin gravatar image

updated 2013-06-20 16:42:42 -0500

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));



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


Asked: 2013-06-20 05:29:18 -0500

Seen: 1,605 times

Last updated: Jun 20 '13