繁体   English   中英

如何计算二维图像的基本矩阵?

[英]How to compute fundamental matrix for 2D images?

我试图找到两个图像之间的基本矩阵。 我的图像中的对应点如下 -

pts1_list = 
   [
    [224.95256042, 321.64755249],
    [280.72879028, 296.15835571],
    [302.34194946, 364.82437134],
    [434.68283081, 402.86990356],
    [244.64321899, 308.50286865],
    [488.62979126, 216.26953125],
    [214.77470398, 430.75869751],
    [299.20846558, 312.07217407],
    [266.94125366, 119.36679077],
    [384.41549683, 442.05865479],
    [475.28448486, 254.28138733]
  ]

  pts2_list = 
  [
    [253.88285828, 335.00772095],
    [304.884552,   308.89205933],
    [325.33914185, 375.91308594],
    [455.15515137, 411.18075562],
    [271.48794556, 322.07028198],
    [515.11816406, 221.74610901],
    [245.31390381, 441.54830933],
    [321.74771118, 324.31417847],
    [289.86627197, 137.46456909],
    [403.3711853,  451.08905029],
    [496.16610718, 261.36074829]
  ]

我找到了一个代码可以满足我的要求,但它看起来只适用于 3D 点。 我已经在此处此处链接了参考代码链接,但从根本上说,我正在查看的代码片段是 -

def compute_fundamental(x1, x2):
  '''Computes the fundamental matrix from corresponding points x1, x2 using
  the 8 point algorithm.'''
  n = x1.shape[1]
  if x2.shape[1] != n:
    raise ValueError('Number of points do not match.')

  # Normalization is done in compute_fundamental_normalized().
  A = numpy.zeros((n, 9))
  for i in range(n):
    A[i] = [x1[0, i] * x2[0, i],  x1[0, i] * x2[1, i],  x1[0, i] * x2[2, i],
            x1[1, i] * x2[0, i],  x1[1, i] * x2[1, i],  x1[1, i] * x2[2, i],
            x1[2, i] * x2[0, i],  x1[2, i] * x2[1, i],  x1[2, i] * x2[2, i],
           ]

  # Solve A*f = 0 using least squares.
  U, S, V = numpy.linalg.svd(A)
  F = V[-1].reshape(3, 3)

  # Constrain F to rank 2 by zeroing out last singular value.
  U, S, V = numpy.linalg.svd(F)
  S[2] = 0
  F = numpy.dot(U, numpy.dot(numpy.diag(S), V))
  return F / F[2, 2] 

def setUp(self):
    points = array([
      [-1.1, -1.1, -1.1], [ 1.4, -1.4, -1.4], [-1.5,  1.5, -1], [ 1,  1.8, -1],
      [-1.2, -1.2,  1.2], [ 1.3, -1.3,  1.3], [-1.6,  1.6,  1], [ 1,  1.7,  1],
      ])
    points = homography.make_homog(points.T)

    P = hstack((eye(3), array([[0], [0], [0]])))
    cam = camera.Camera(P)
    self.x = cam.project(points)

    r = [0.05, 0.1, 0.15]
    rot = camera.rotation_matrix(r)
    cam.P = dot(cam.P, rot)
    cam.P[:, 3] = array([1, 0, 0])
    self.x2 = cam.project(points)

    def testComputeFundamental(self):
      E = sfm.compute_fundamental(self.x2[:, :8], self.x[:, :8])

在此代码中,传递的参数是 3 维的,而我的要求只是一个双坐标系。 我想知道如何修改此代码以及在我的情况下应如何计算 A 矩阵。 谢谢你。

F, _ = cv2.findFundamentalMat(pts1_list, pts2_list)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM