How to do it

You need to complete the following steps:

  1. Import the necessary modules:
import cv2
import numpy as np
  1. Load the precomputed homography and camera parameters:
data = np.load('../data/rotational_homography.npy').item()
H, K = data['H'], data['K']
  1. Factor out the camera parameters from the homography transformation:
H_ = np.linalg.inv(K) @ H @ K
  1. Compute the approximate rotation matrix:
w, u, vt = cv2.SVDecomp(H_)
R = u @ vt
if cv2.determinant(R) < 0:
R *= 1
  1. Convert the rotation matrix to the rotation vector:
rvec = cv2.Rodrigues(R)[0]
  1. Print the results:
print('Rotation vector:')
print(rvec)