我们先来看opencv给出的一个教程[ http://docs.opencv.org/3.1.0/dd/d53/tutorial_py_depthmap.html ]里面对概念的说明。先看下面这张图:
通过这张图,我们得出视差的计算表达式为:
disparity=x−x′=BFZ
其中
x 和
x′ 对应的是场景中的3D点和相机中心在图像平面上的投影点的距离,stack flow上面的回答[ http://stackoverflow.com/questions/17607312/difference-between-disparity-map-and-disparity-image-in-stereo-matching ]更加准确,这个稍后再来参考。
B 是两个相机中心的距离,
f 是相机的焦距,
Z 就是对应点的深度了(作者在这儿选择Z代表深度,应该也是想要表达深度是Z轴方向的距离)。通过上面的表达式我们也能看出来深度和视差成反比。下面再来理解下视差这个概念。下面的英文讲解得相当透彻,就不多此一举翻译成中文了。
Disparity refers to the distance between two corresponding points in the left and right image of a stereo pair. If you look at the image below you see a labelled point X (ignore X1, X2 & X3). By following the dotted line from X to OL you see the intersection point with the left hand plane at XL. The same principal applies with the right-hand image plane.
If X projects to a point in the left frame XL = (u,v) and to the right frame at XR = (p,q) you can find the disparity for this point as the magnitude of the vector between (u,v) and (p,q). Obviously this process involves choosing a point in the left hand frame and then finding its match (often called the corresponding point) in the right hand image; often this is a particularly difficult task to do without making a lot of mistakes.