How to do it

You need to complete the following steps:

  1. Import the necessary modules:
import cv2import numpy as npimport matplotlib.pyplot as plt
  1. Load the stereo rig calibration parameters:
data = np.load('../data/stereo/case1/stereo.npy').item()Kl, Dl, Kr, Dr, R, T, img_size = data['Kl'], data['Dl'], data['Kr'], data['Dr'], \                                 data['R'], data['T'], data['img_size']
  1. Load the left and right test images:
left_img = cv2.imread('../data/stereo/case1/left14.png')right_img = cv2.imread('../data/stereo/case1/right14.png')
  1. Estimate the stereo rectification parameters:
R1, R2, P1, P2, Q, validRoi1, validRoi2 = cv2.stereoRectify(Kl, Dl, Kr, Dr,                                                             img_size, R, T)
  1. Prepare the stereo rectification transformation maps:
xmap1, ymap1 = cv2.initUndistortRectifyMap(Kl, ...

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.