The results obtained by MGM are converted into depth maps.
Closed this issue · 2 comments
Hello, MGM is a great algorithm. The result is a disparity map. How can I turn it into a depth map? I mean, do I need to use the formula Z=f*B/d? Do the disparity in the formula need to be scaled? I just started multi-view stereo, so I'm not sure.
Hi, yes you need to use that formula,
https://docs.opencv.org/4.x/dd/d53/tutorial_py_depthmap.html
however some of the parameters are not evident. In that formula all terms are in meters or millimeters, but your disparity is in pixels. For converting your pixels you'd need to multiply you disparity d with the pixel pitch (the size of a pixel in nm) :(
On the other hand you also need the real focal length f, which is in mm but not easy to figure out. :(
All these parameters would be computed during camera calibration.
But luckily there's a rule of thumb that says: the focal length is usually half the sensor width (let's say 3000 px times the unknown pixel pitch). Since one is multiplying and the other is dividing then the pixel pitch simplifies out you get something like
Z = 1500* B / d,
where 1500 is half your sensor width, B is your baseline in meters, and Z your depth in meters. This would give you reasonable quantities. Then you can calibrate the value 1500 to match your real measurement.
Thank you for your patient reply, which has benefited me a lot. After the test, I think the depth map was generated successfully. Thank you again for your answer.