Skip to content

Instantly share code, notes, and snippets.

@HViktorTsoi
Last active September 9, 2022 03:12
Show Gist options
  • Save HViktorTsoi/20c2f746a57abd0c3d0c49d7714e3b09 to your computer and use it in GitHub Desktop.
Save HViktorTsoi/20c2f746a57abd0c3d0c49d7714e3b09 to your computer and use it in GitHub Desktop.
opencv python 3d->2d omni projection
import cv2
import numpy as np
import matplotlib.pyplot as plt
K = np.array([
[1377.4254511359, 0, 1054.3015274037],
[0, 1373.0788259424, 760.6952319349],
[0, 0, 1],
]).astype(np.float32)
D = np.array([-0.5522170592, 0.2365604514, 0.0021662078, -0.0028341398]).astype(np.float32)
xi = 0.8299270097
rvec = np.array([0, 0, 0]).astype(np.float32)
tvec = np.array([0, 0, 0]).astype(np.float32)
xx, yy = np.meshgrid(np.arange(-3, 3, 0.1), np.arange(-3, 3, 0.1))
points_3d = np.row_stack([xx.reshape(-1), yy.reshape(-1), np.ones(xx.shape[0] * xx.shape[1])]).T
points_2d, jac = cv2.omnidir.projectPoints(np.expand_dims(points_3d, -2).astype(np.float32), rvec, tvec, K, xi, D)
points_2d = np.squeeze(points_2d)
plt.scatter(points_2d[:, 0], points_2d[:, 1])
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment