-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_epi.py
64 lines (50 loc) · 1.76 KB
/
plot_epi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import cv2
def plot_lines(lines, h, w):
""" Utility function to plot lines
"""
for i in range(lines.shape[1]):
# plt.close('all')
if abs(lines[0, i] / lines[1, i]) < 1:
y0 = -lines[2, i] / lines[1, i]
yw = y0 - w * lines[0, i] / lines[1, i]
plt.plot([0, w], [y0, yw])
# plt.clf()
# plt.show()
# plt.savefig(filename)
else:
x0 = -lines[2, i] / lines[0, i]
xh = x0 - h * lines[1, i] / lines[0, i]
plt.plot([x0, xh], [0, h])
# plt.clf
# plt.show()
# plt.savefig(filename)
def plot_epipolar_lines(image1, image2, uncalibrated_1, uncalibrated_2, E, K, plot=True):
""" Plots the epipolar lines on the images
"""
""" YOUR CODE HERE
"""
K_inv = np.linalg.inv(K)
K_invt = K_inv.T
F = K_invt @ E @ K_inv # fundamental matrix
# compute epipolar lines in images 1 and 2
epipolar_lines_in_1 = (uncalibrated_2.T @ F).T
epipolar_lines_in_2 = (uncalibrated_1.T @ F.T).T
""" END YOUR CODE
"""
if(plot):
plt.figure(figsize=(6.4*3, 4.8*3))
ax = plt.subplot(1, 2, 1)
ax.set_xlim([0, image1.shape[1]])
ax.set_ylim([image1.shape[0], 0])
plt.imshow(image1[:, :, ::-1])
plot_lines(epipolar_lines_in_1, image1.shape[0], image1.shape[1])
ax = plt.subplot(1, 2, 2)
ax.set_xlim([0, image1.shape[1]])
ax.set_ylim([image1.shape[0], 0])
plt.imshow(image2[:, :, ::-1])
plot_lines(epipolar_lines_in_2, image2.shape[0], image2.shape[1])
else:
return epipolar_lines_in_1, epipolar_lines_in_2