Epipole from essential matrix:
e1c2 is the position of camera 2 in image 1 coordinates. (Plot it in image 1)
def epipoleSVD(M): V = cv2.SVDecomp(M)[2] return V[-1]/V[-1,-1] e1c2 = epipoleSVD(E) e2c1 = epipoleSVD(E.T)
Note: This cv2 method returns three values, [S, U, V], but only V is needed to find the epipole. The epipole is in form [x,y,1].
Epipolar lines from essential matrix:
elines1 (a 3xN array) are drawn on image 1 and will converge at e1c2 (from above). x1 and x2 are normalized 3xN arrays of corresponding points in image 1 and image 2. (A line vector contains the values [a,b,c] in ax+by+c=0)
elines2 = dot(E, x1) elines1 = dot(E.T, x2) #or dot(x2.T, E).T
To plot these lines, try the following:
def lines2points(lines, epipole): xmax = ones(lines.shape[1])*epipole[0] a,c = lines[0]/lines[1], lines[2]/lines[1] x = array([-xmax,xmax]) y = array([r_[-a*Lx[0] - c], r_[-a*Lx[1] - c]]) return x, y Lx,Ly = lines2points( dot(E, x1), epipoleSVD(E.T) ) plt.plot(Lx, Ly, 'r')
Note: This will overlay epipolar lines derived from image 1 on corresponding points in image 2 that are between +/- epipole x-coordinate.