Hi,
I have been testing the fundamental matrix estimation with different robust estimators, such as RANSAC and USAC (MAGSAC++), using opencv-python. For testing, I similarly used the code from this tutorial example and included the estimator as follows:
ransacReprojThreshold = 3.0
confidence = 0.99
maxIters = 500
F, status = cv2.findFundamentalMat(pts1, pts2, cv2.USAC_MAGSAC, ransacReprojThreshold, confidence, maxIters)
# F, status = cv2.findFundamentalMat(pts1, pts2, cv2.FM_RANSAC, ransacReprojThreshold, confidence, maxIters)
if F is None or F.shape == (1, 1):
print('No fundamental matrix found')
return np.zeros((3, 3, 1), dtype = "uint8"), 0
if F.shape[0] > 3:
# more than one matrix found, just pick the first
print('More than one matrix found')
print(F)
F = F[0:3, 0:3]
ninliers = np.sum(status)
if ninliers >= min_num_inliers:
return F, ninliers
else:
return np.zeros((3, 3, 1), dtype = "uint8"), ninliers
I run the code 100 times on two example images from the public EuRoC MAV Dataset (Machine Hall 05, frames 470 and 480). I was expecting to obtain different results for each run due to the sampling approach of the estimators (RANSAC, MAGSAC), but the results were always the same. Note that the values of the parameters confidence, reprojection error, max iterations, and minimum number of inliers are kept fixed across runs.
Have anybody experienced the same behaviour? Is there any issue or random seed set inside OpenCV code that causes this behaviour?
My setup
OpenCV: 4.5.5
Python: 3.10
Ubuntu 18.04 LTS