How to do it

You need to complete the following steps:

  1. Import the necessary modules.
import cv2import numpy as np
  1. Generate the test camera's projection matrices:
P1 = np.eye(3, 4, dtype=np.float32)P2 = np.eye(3, 4, dtype=np.float32)P2[0, 3] = -1
  1. Generate the test points:
N = 5points3d = np.empty((4, N), np.float32)points3d[:3, :] = np.random.randn(3, N)points3d[3, :] = 1
  1. Project the 3D points into two views and add noise:
points1 = P1 @ points3dpoints1 = points1[:2, :] / points1[2, :]points1[:2, :] += np.random.randn(2, N) * 1e-2points2 = P2 @ points3dpoints2 = points2[:2, :] / points2[2, :]points2[:2, :] += np.random.randn(2, N) * 1e-2
  1. Reconstruct the points from noisy observations:
points3d_reconstr = cv2.triangulatePoints(P1, ...

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.