Created
July 27, 2021 14:30
-
-
Save yangyushi/45467fd90580b718682e13fbdf006beb to your computer and use it in GitHub Desktop.
different ways to calculate the essential matrix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
p1 = np.random.random((100, 2)) # feature points in camera 1 | |
p2 = np.random.random((100, 2)) # feature points in camera 1 | |
# camera matrices | |
k1 = np.random.random((3, 3)) | |
k2 = np.random.random((3, 3)) | |
# Method 1: calculate essential matrix (E) from the fundamental matrix (F) | |
F, _ = cv2.findFundamentalMat(p1, p2, cv2.FM_LMEDS) | |
E = k2.T @ F @ k1 # -> the singular value of E is typically not (sigma, sigma, 0) | |
# Method 2: calculate E directly from normalised feature points | |
p1h = np.concatenate((p1.T, np.ones(n).reshape((1, n)))) # homogeneous representation | |
p2h = np.concatenate((p2.T, np.ones(n).reshape((1, n)))) | |
p1hn = np.linalg.inv(c1.k) @ p1h # normalisation | |
p2hn = np.linalg.inv(c2.k) @ p2h | |
E, _ = cv2.findFundamentalMat(p1hn.T, p2hn.T) | |
# Method 3: use opencv's 5-point algorithm | |
E, _ = cv2.findEssentialMat( | |
p1, p2, | |
cameraMatrix1=c1.k, | |
distCoeffs1=np.zeros(5), | |
cameraMatrix2=c2.k, | |
distCoeffs2=np.zeros(5) | |
) # -> the singular value of E is (sigma, sigma, 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment