Rotational camera case - estimating camera rotation from homography
In this recipe, you will learn how to extract rotation from a homography transformation between two views captured by a camera undergoing only rotation motion with respect to its optical center. This is useful if, for example, you need to estimate the rotation between two views, assuming that the translation is negligible compared to distances to scene points. That's often the case in landscape photo stitching.
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 precomputed homography and camera parameters:
data = np.load('../data/rotational_homography.npy').item() H, K = data['H'], data['K']
- Factor out the camera parameters from the homography transformation:
H_ = np.linalg.inv(K) @ H @ K
- Compute the approximate rotation matrix:
w, u,...