Skip to content

Commit

Permalink
adding a custom triangulation function cause OpenCV sucks!
Browse files Browse the repository at this point in the history
  • Loading branch information
“Akbonline” committed Oct 30, 2020
1 parent 640aaf6 commit 681bb1b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions triangulation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import cv2
import numpy as np

#Recreating bunch of points using Triangulation
#Given the relative poses, calculating the 3d points
def triangulate(pose1, pose2, pts1, pts2):

ret = np.zeros((pts1.shape[0], 4))
pose1 = np.linalg.inv(pose1)
pose2 = np.linalg.inv(pose2)
for i, p in enumerate(zip(pts1, pts2)):
A = np.zeros((4,4))
A[0] = p[0][0] * pose1[2] - pose1[0]
A[1] = p[0][1] * pose1[2] - pose1[1]
A[2] = p[1][0] * pose2[2] - pose2[0]
A[3] = p[1][1] * pose2[2] - pose2[1]
_, _, vt = np.linalg.svd(A)
ret[i] = vt[3]
return ret

0 comments on commit 681bb1b

Please sign in to comment.