title: OpenCv depth estimation from Disparity map
body: <p>I'm trying to estimate depth from a stereo pair images with OpenCV. I have disparity map and depth estimation can be obtained as:</p>
  
  <pre><code>             (Baseline*focal)
  depth  =     ------------------
             (disparity*SensorSize)
  </code></pre>
  
  <p>I have used Block Matching technique to find the same points in the two rectificated images.
  OpenCV permits to set some block matching parameter, for example <code>BMState-&gt;numberOfDisparities</code>. </p>
  
  <p>After block matching process:</p>
  
  <pre><code>cvFindStereoCorrespondenceBM( frame1r, frame2r, disp, BMState);
  cvConvertScale( disp, disp, 16, 0 );
  cvNormalize( disp, vdisp, 0, 255, CV_MINMAX );
  </code></pre>
  
  <p>I found depth value as:</p>
  
  <pre><code>if(cvGet2D(vdisp,y,x).val[0]&gt;0)
     {
     depth =((baseline*focal)/(((cvGet2D(vdisp,y,x).val[0])*SENSOR_ELEMENT_SIZE)));
     }
  </code></pre>
  
  <p>But the depth value obtaied is different from the value obtaied with the previous formula due to the value of <code>BMState-&gt;numberOfDisparities</code> that changes the result value.</p>
  
  <p>How can I set this parameter? what to change this parameter?</p>
  
  <p>Thanks</p>