How to do it...

You need to complete the following steps:

  1. Import the modules:
import cv2import numpy as np
  1. Generate an initial points set. Then create a set of rotated points by applying a rotation matrix to the initial points. Also, add a portion of noise to our rotated points:
pts = np.random.multivariate_normal([150, 300], [[1024, 512], [512, 1024]], 50)rmat = cv2.getRotationMatrix2D((0, 0), 30, 1)[:, :2]rpts = np.matmul(pts, rmat.transpose())rpts_noise = rpts + np.random.multivariate_normal([0, 0], [[200, 0], [0, 200]], len(pts))
  1. Solve the orthogonal Procrustes problem using Singular Value Decomposition (SVD) and get an estimate of the rotation matrix:
M = np.matmul(pts.transpose(), rpts_noise)sigma, u, v_t = cv2.SVDecomp(M)rmat_est ...

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.