我有以下代码通过将给定点乘以基本矩阵来计算和呈现核线:
# This should open a new figure window outside of jupyter notebook
%matplotlib qt
imL = cv2.imread('Left.tif', cv2.IMREAD_GRAYSCALE)
imR = cv2.imread('Right.tif', cv2.IMREAD_GRAYSCALE)
plt.rcParams['figure.figsize'] = (14.0, 14.0)
f, ((ax1, ax2)) = plt.subplots(1, 2, sharex='col', sharey='row')
ax1.imshow(imL, cmap='gray'), ax1.set_title('Left image')
ax2.imshow(imR, cmap='gray'), ax2.set_title('Right image')
data = plt.ginput(3)
x_val = [x[0] for x in data]
y_val = [x[1] for x in data]
ax2.scatter(x_val, y_val, color='r')
for x in data:
Lleft = np.matmul(np.append(x,1).T,F)
y_0 = -Lleft[2]/Lleft[1]
x_width = imL.shape[1]
y_width = -(Lleft[2] + Lleft[0]*x_width)/Lleft[1]
ax1.plot((0, x_width),(y_0, y_width))
Lright = np.matmul(F,np.append(x,1))
y_0 = -Lright[2]/Lright[1]
x_width = imR.shape[1]
y_width = -(Lright[2] + Lright[0]*x_width)/Lright[1]
ax2.plot((0, x_width),(y_0, y_width))
最底部(在 for 循环内)应该显示原始图像上的极线,因此这些线必须像这样穿过这些点:
知道为什么会这样吗?