Search code examples
graphicsopencvcomputer-visionstereo-3d

Error getting 3D points from Disparity


So I calculate the disparity between 2 stereo images(left and right).It looks correct (because it is somewhat similar in shape to the original image).After this I use the line :-

cvReprojectImageTo3D(&disparity, threeDimage, &Q);

and get the answers in threeDimage.It is a matrix and I access it as :-

for(int ii=0;ii<threeDimage->rows;ii++)
    {       
    float *data = (float *)(threeDimage->data.ptr + ii * threeDimage->step);

    for(int jj=0;jj<threeDimage->cols*3;jj=jj+3) 
   {


      float a=data[jj];
      float b=data[jj+1];
      float c=data[jj+2];
      fprintf(fpp,"%f %f %f \n", a,b,c);

       }

}

But the problem is it doesnt seem to give me a correct answer.I get lot of repeated values in my file.Any hint on what might be going wrong?Is the traversal of the matrix correct?


Solution

  • You can only get a different 3D distance from points where there is an edge in the disparity map. If you have large areas of the same disparity (flat grey in the input image) then they will have the same Z.