Ask Your Question
0

Disparity image reconstruction

asked 2014-11-17 03:00:23 -0500

Robot gravatar image

updated 2014-11-18 01:28:32 -0500

Miquel Massot gravatar image

I am using two prosilica cameras in order to generate the disparity image. by the help of stereo_image_proc I can generate the disparity image and is available in /stereo/disparity_image topic. Now in another node I am reconstructing the disparity image using raw data[].

int count = 0;
sensor_msgs::Image img = disp.image;
int h = (img.height);
int w = (img.width);
cv::WImageBuffer3_b pic(h,w);
ROS_INFO("height width and step [%d]  [%d]  [%d]" ,img.height,img.width,img.step);
count = 0; 
for(int i=(h-1);i>=0;i--) {
   for(int j=(w-1);j>=0;j--)  { 
      count++;
      *(pic(i,j)) = (img.data[count]);
      count++;
      *(pic(i,j)+1) = (img.data[count]);
      count++;   
      *(pic(i,j)+2) = (img.data[count]);
      count++;
  }
}

for each set of pixel data I am ignoring one data as it provides the depth.. during viewing the reconstructed image only the colors get swaped. that menas the portion with green switched to some other color and so on..

edit retag flag offensive close merge delete

Comments

in the DosparityImage format there is a fuled name Image. In Image field there is data[]. is that data contains RGB and Depth info raw data of the iamge or something else.. thanks in advance ????

Robot gravatar imageRobot ( 2014-11-17 03:22:16 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-11-17 12:36:55 -0500

Robot gravatar image

updated 2014-11-18 01:31:07 -0500

Miquel Massot gravatar image

I solved the problem. The data available in the disparity image is not the RGB values. Those are encoded in TYPE_32FC1 so inorder to reconstruct the image we have to use some colormap done in stereo_view node in the image_view package. just subscribe the topic where the disparity image is available.

void imageCallback(const stereo_msgs::DisparityImageConstPtr& disp) {
  Mat_ Vec3b disparity_color_;
  float min_disparity = disp->min_disparity;
  float max_disparity = disp->max_disparity;
  float multiplier = 255.0f / (max_disparity - min_disparity);
  assert(disp->image.encoding == sensor_msgs::image_encodings::TYPE_32FC1);
  const cv::Mat_<float> dmat(disp->image.height, disp->image.width,
                             (float*)&disp->image.data[0], disp->image.step);
  disparity_color_.create(disp->image.height, disp->image.width);

  for (int row = 0; row < disparity_color_.rows; ++row) {
    const float* d = dmat[row];
    for (int col = 0; col < disparity_color_.cols; ++col) {
      int index = (d[col] - min_disparity) * multiplier + 0.5;
      index = std::min(255, std::max(0, index));
      // Fill as BGR
      disparity_color_(row, col)[2] = colormap[3*index + 0];
      disparity_color_(row, col)[1] = colormap[3*index + 1];
      disparity_color_(row, col)[0] = colormap[3*index + 2];
    }
  }
  imshow( "view", disparity_color_ );
}
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

Stats

Asked: 2014-11-17 03:00:23 -0500

Seen: 423 times

Last updated: Nov 18 '14