簡體   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