How to do it...

You need to complete the following steps:

  1. Import the modules:
import cv2import numpy as np
  1. Generate a system of linear equations:
N = 10A = np.random.randn(N,N)while np.linalg.matrix_rank(A) < N:    A = np.random.randn(N,N)x = np.random.randn(N,1)b = A @ x
  1. Solve the system of linear equations:
ok, x_est = cv2.solve(A, b)print('Solved:', ok)if ok:    print('Residual:', cv2.norm(b - A @ x_est))    print('Relative error:', cv2.norm(x_est - x) / cv2.norm(x))
  1. Construct an over-determined system of linear equations:
N = 10A = np.random.randn(N*2,N)while np.linalg.matrix_rank(A) < N:    A = np.random.randn(N*2,N)x = np.random.randn(N,1)b = A @ x
  1. Solve the over-determined system of linear equations:
ok, x_est = cv2.solve(A, b, flags=cv2.DECOMP_NORMAL) ...

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.