Estimating disparity maps for stereo images
In this recipe, you will learn how to compute a disparity map from two rectified images. This functionality is useful in many computer vision applications where you need to recover information about depth in a scene, for example, collision avoidance in advanced driver assistance applications.
Getting ready
Before you proceed with this recipe, you need to install the OpenCV version 3.3 (or greater) Python API package.
How to do it
You need to complete the following steps:
- Import the necessary modules:
import cv2 import numpy as np
- Load the left and right rectified images:
left_img = cv2.imread('../data/stereo/left.png') right_img = cv2.imread('../data/stereo/right.png')
- Compute the disparity map using the stereo block matching algorithm:
stereo_bm = cv2.StereoBM_create(32) dispmap_bm = stereo_bm.compute(cv2.cvtColor(left_img, cv2.COLOR_BGR2GRAY), cv2.cvtColor(right_img, cv2.COLOR_BGR2GRAY))
- Compute the disparity map using the...