基础
disparity=x-x’=Bf/Z 推出图像中所有点的深度图。
x,x’:图像中的点到3D空间中的点和到摄像机中心的距离。
B:两摄像机之间的距离。
f:摄像机的焦距。
点的深度与x和x‘的差成反比。
代码演示
#coding=utf-8
import cv2
import numpy as np
from matplotlib import pyplot as plt
img1=cv2.imread(’./image2/mario.jpg’,0)
img2=cv2.imread(’./image2/coin.jpg’,0)
stereo=cv2.createStereoBM(numDisparities=16,blockSize=15)
disparity=stereo.compute(img1,img2)
plt.imshow(disparity,‘gray’)
plt.show()