How it works

We use two different algorithms for disparity maps calculation—block matching and semi-global block matching. After the map estimation object is instantiated using either cv2.StereoBM_create or cv2.StereoSGBM_create (where we specify maximum possible disparity), we call the compute method, which takes two images and returns a disparity map.

Note that it's necessary to pass rectified images as input to the compute method. The returned disparity map will contain per-pixel disparity values, for example, a horizontal offset in pixels between the left and right image points corresponding to the same point in the scene. That offset then can be used to restore an actual point in 3D.

When creating a disparity estimator, you can specify ...

Get OpenCV 3 Computer Vision with Python Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.