Aligning two views through stereo rectification
In this recipe, you will learn how to rectify two images captured using a stereo camera with known parameters in such a way that, for the point (xl, yl) in the left image, the corresponding epipolar line in the right image is yr=yl and vice versa. This greatly simplifies feature matching and dense stereo estimation algorithms.
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 import matplotlib.pyplot as plt
- 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']
- Load the left and right test images:
left_img = cv2.imread('../data/stereo/case1/left14.png') right_img ...