Stereo vision: Depth estimation
Asked Answered
G

1

9

I am working on Stereo vision task and I would like to get the distance between stereo vision cameras and the object. I am using Matlab with Computer Vision System Toolbox.
I have calibrated cameras with using "Camera Calibration Toolbox for Matlab" thus I have Intrinsic parameters of left and right camera and Extrinsic parameters (position of right camera wrt left camera). I have also a pair of rectified pictures and thier disparity map. For estimation of disparity I have used Matlab function disparity(). I know the baseline and the focal length of cameras but my results are still wrong.

baseline = 70 mm
focal length = 25 mm
disparity = 60 pixels
---------------------
depth = baseline * focal length / disparity = 70 * 25 / 60 = 29 mm

But I know that the distance is cca 600 mm. Is this formula right? What about the units? mm * mm / pixel != mm. And especially I would like to use Camera matrix (Intrinsic parameters) for calculation but I didn't figure out how. I would be thankful for any hint.

Gogh answered 13/11, 2013 at 14:54 Comment(0)
G
8

Like you said, you have to convert the unit into mm. And for that you need this formulas

z = (b*F) / (d*s)

mm = (mm * mm) / (pixel * (mm/pixel)) 

Where

  • z = depth in mm
  • b = baseline in mm
  • F = focal length in mm
  • d = depth in pixel
  • s = sensor size in mm/pixel. (Normally it provide in um, so do conversion before).

EDIT

Sometime your focal is in pixel so you don't need to use the sensor size. So just use your formula :

z = b*F / d
mm = mm * pixel / pixel
Ghostly answered 13/11, 2013 at 15:3 Comment(10)
You can have detail of this formula hereGhostly
Careful with your bracketing there; do you mean z = b*F/d*s or z = b*F / (d*s)?Paintbrush
Thanks @Alexandre this part is solved but unfortunately results are not better. Because I am sure about baseline, focal length and pixel size, disparity estimation probably isn't so accurate. And please do you know how to implement Camera matrix into this calculation?Gogh
@Gogh I think what you are looking for is that : Homography, this article explain a little, but try to search for homography for more informations. And maybe you disparity map isn't good. Is it looking well ?Ghostly
@Alexandre Please could you help me with the conversion of sensor size? I found in the camera specs parameters Image sensor: 2/3 (type progressive scan IT CCD), Cell size (H x V): 3.45 x 3.45 um - I assume it is "pixel size". And the resolution of picture is 2448 x 2048 pixels.Gogh
@Gogh You're right. Cell size means the size of a pixel in um. So you have a 0.00345 mm/pixel cell.Ghostly
@Alexandre I have two rectified images. I can determine same point on both of them. On the left image the point has coordinates LX: 1472, LY: 742, on the right image RX:1589, RY: 742. I will get Disparity = RX - LX = 1589 - 1472 = 114 pixels. Baseline is 50 mm, Focal length is 12.5 mm (it is written on the lens of camera) and Pixel size is 0.00345 mm/pixel. Z = (baseline * focal length) / (disparity * pixel size) = (50 * 12.5) / (114 * 0.00345) = 1589 mm. But I know that the distance is 800 mm. Am I doing something wrong?Gogh
Nothing. Theory is always good. But practice never giving what we really want. Can you found the focal in pixel ? To use Z = fB/d ?Ghostly
@Alexandre Thanks a lot for your help. At the end I have used different scenario which is more accurate. I calibrated pairs of cameras with Camera Calibration Toolbox for Matlab from Caltech. Inside this Toolbox are functions for image rectification and stereo triangulation. Calculation is based on intrinsics and extrinsic parameters exported from Toolbox then results have higher accuracy.Gogh
Yes, the Focal is in pixel :) I like this toolbox. I'm using it a lot in my work.Ghostly

© 2022 - 2024 — McMap. All rights reserved.