Ask Your Question

Revision history [back]

Wrong rank in Fundamental Matrix

Hi guys,

I'm using the OpenCV for Python3 and, based on the Mastering OpenCV Book, try to compute the epipoles from many images (Structure from Motion algorithm).

In many books, they say which Fundamental Matrix has rank 2. But, the OpenCV function returns a rank 3 matrix.

How can I make this right?

  orb = cv2.ORB_create()

  # find the keypoints and descriptors with ORB
  kp1, des1 = orb.detectAndCompute(img1,None)
  kp2, des2 = orb.detectAndCompute(img2,None)

  # create BFMatcher object
  bf = cv2.BFMatcher(cv2.NORM_L2, crossCheck=True)

  # Match descriptors.
  matches = bf.match(des1,des2)

  # Sort them in the order of their distance.
  matches = sorted(matches, key = lambda x:x.distance)

  pts1 = []
  pts2 = []
  for m in matches:
      pts2.append(kp2[m.trainIdx].pt)
      pts1.append(kp1[m.queryIdx].pt)

  F, mask = cv2.findFundamentalMat(pts1, pt2,cv2.FM_RANSAC)
  pts1 = match['leftPts'][mask.ravel()==1]
  pts2 = match['rightPts'][mask.ravel()==1]
  # F is the Fundamental Matrix

From that code, the output are like

Processing image 0 and image 1
rank of F: 3
Processing image 0 and image 2
rank of F: 3
Processing image 0 and image 3
rank of F: 3
Processing image 0 and image 4
rank of F: 2
[...]

Someone could help me? Someone have any functional code for SfM using OpenCV? Thanks in advance.