OpenCV
4.6.0dev
Open Source Computer Vision

author:
The integrated part to OpenCV calib3d
module is RANSACbased universal framework USAC (namespace usac
) written in C++. The framework includes different stateofthearts methods for sampling, verification or local optimization. The main advantage of the framework is its independence to any estimation problem and modular structure. Therefore, new solvers or methods can be added/removed easily. So far it includes the following components:
solvePnPRansac(...)
with UsacParams
there is an options to pass empty intrinsic matrix InputOutputArray cameraMatrix
. If matrix is empty than using Direct Linear Transformation algorithm (PnP with 6 points) framework outputs not only rotation and translation vector but also calibration matrix.Also, the framework can be run in parallel. The parallelization is done in the way that multiple RANSACs are created and they share two atomic variables bool success
and int num_hypothesis_tested
which determines when all RANSACs must terminate. If one of RANSAC terminated successfully then all other RANSAC will terminate as well. In the end the best model is synchronized from all threads. If PROSAC sampler is used then threads must share the same sampler since sampling is done sequentially. However, using default options of framework parallel RANSAC is not deterministic since it depends on how often each thread is running. The easiest way to make it deterministic is using PROSAC sampler without SPRT and Local Optimization and not for Fundamental matrix, because they internally use random generators.\ \ For NAPSAC, Progressive NAPSAC or GraphCut methods is required to build a neighborhood graph. In framework there are 3 options to do it:
NEIGH_FLANN_KNN
– estimate neighborhood graph using OpenCV FLANN K nearestneighbors. The default value for KNN is 7. KNN method may work good for sampling but not good for GCRANSAC.NEIGH_FLANN_RADIUS
– similarly as in previous case finds neighbor points which distance is less than 20 pixels.NEIGH_GRID
– for finding points’ neighborhood tiles points in cells using hashtable. The method is described in [2]. Less accurate than NEIGH_FLANN_RADIUS
, although significantly faster.Note, NEIGH_FLANN_RADIUS
and NEIGH_FLANN_RADIUS
are not able to PnP solver, since there are 3D object points.\ \ New flags:
USAC_DEFAULT
– has standard LORANSAC.USAC_PARALLEL
– has LORANSAC and RANSACs run in parallel.USAC_ACCURATE
– has GCRANSAC.USAC_FAST
– has LORANSAC with smaller number iterations in local optimization step. Uses RANSAC score to maximize number of inliers and terminate earlier.USAC_PROSAC
– has PROSAC sampling. Note, points must be sorted.USAC_FM_8PTS
– has LORANSAC. Only valid for Fundamental matrix with 8points solver.USAC_MAGSAC
– has MAGSAC++.Every flag uses SPRT verification. And in the end the final sofarthebest model is polished by non minimal estimation of all found inliers.\ \ A few other important parameters:
randomGeneratorState
– since every USAC solver is deterministic in OpenCV (i.e., for the same points and parameters returns the same result) by providing new state it will output new model.loIterations
– number of iterations for Local Optimization method. The default value is 10. By increasing loIterations
the output model could be more accurate, however, the computationial time may also increase.loSampleSize
– maximum sample number for Local Optimization. The default value is 14. Note, that by increasing loSampleSize
the accuracy of model can increase as well as the computational time. However, it is recommended to keep value less than 100, because estimation on low number of points is faster and more robust.Samples:
There are three new sample files in opencv/samples directory.
epipolar_lines.cpp
– input arguments of main
function are two paths to images. Then correspondences are found using SIFT detector. Fundamental matrix is found using RANSAC from tentative correspondences and epipolar lines are plot.essential_mat_reconstr.cpp
– input arguments are path to data file containing image names and single intrinsic matrix and directory where these images located. Correspondences are found using SIFT. The essential matrix is estimated using RANSAC and decomposed to rotation and translation. Then by building two relative poses with projection matrices image points are triangulated to object points. By running RANSAC with 3D plane fitting object points as well as correspondences are clustered into planes.essential_mat_reconstr.py
– the same functionality as in .cpp file, however instead of clustering points to plane the 3D map of object points is plot.References:
1. Daniel Barath and Jiří Matas. 2018. GraphCut RANSAC. In Proceedings of the iEEE conference on computer vision and pattern recognition, 6733–6741.
2. Daniel Barath, Maksym Ivashechkin, and Jiri Matas. 2019. Progressive NAPSAC: Sampling from gradually growing neighborhoods. arXiv preprint arXiv:1906.02295.
3. Daniel Barath, Jana Noskova, Maksym Ivashechkin, and Jiri Matas.
4. O. Chum and J. Matas. 2005. Matching with PROSACprogressive sample consensus. In Computer vision and pattern recognition.
5. O. Chum, J. Matas, and J. Kittler. 2003. Locally optimized RANSAC. In Joint pattern recognition symposium.
6. O. Chum, T. Werner, and J. Matas. 2004. Epipolar geometry estimation via RANSAC benefits from the oriented epipolar constraint. In International conference on pattern recognition.
7. Ondrej Chum, Tomas Werner, and Jiri Matas. 2005. Twoview geometry estimation unaffected by a dominant plane. In 2005 iEEE computer society conference on computer vision and pattern recognition (cVPR’05), 772–779.
8. M. A. Fischler and R. C. Bolles. 1981. Random sample consensus: A paradigm for model fitting with applications to image analysis and automated cartography. Communications of the ACM.
9. Jiri Matas and Ondrej Chum. 2005. Randomized RANSAC with sequential probability ratio test. In Tenth iEEE international conference on computer vision (iCCV’05) volume 1, 1727–1732.
10. D. R. Myatt, P. H. S. Torr, S. J. Nasuto, J. M. Bishop, and R. Craddock. 2002. NAPSAC: High noise, high dimensional robust estimation. In In bMVC02, 458–467.
11. Henrik Stewénius, Christopher Engels, and David Nistér. 2006. Recent developments on direct relative orientation.