Package com.irurueta.ar.sfm
Class PlanarBestFundamentalMatrixEstimatorAndReconstructor
java.lang.Object
com.irurueta.ar.sfm.PlanarBestFundamentalMatrixEstimatorAndReconstructor
This class takes matched pairs of 2D points corresponding to a planar scene,
estimates an homography relating both sets of points, decomposes such
homography induced by the 3D plane on the scene, and uses such decomposition
to determine the best epipolar geometry (e.g. fundamental matrix) by using
the essential matrix and provided intrinsic camera parameters on both views
corresponding to both sets of points to reconstruct points and choose the
solution that produces the largest amount of points located in front of both
cameras.
This class requires 2 sets of matched 2D points and the intrinsic parameters
of the cameras in both views, hence cameras must be calibrated in some way
before using this class.
This class is similar to PlanarFundamentalMatrixEstimator but picks the best
solution by reconstructing the 3D points in the scene and choosing the
solution that produces the largest amount of points located in front of both
cameras.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate CorrectorType
Type of corrector to use to triangulate matched points using the corresponding essential matrix or null if no corrector needs to be used.private com.irurueta.geometry.PinholeCamera
Best estimated camera for left view.private com.irurueta.geometry.PinholeCamera
Best estimated camera for right view.private FundamentalMatrix
Best estimated fundamental matrix.private com.irurueta.geometry.ProjectiveTransformation2D
Estimated homography.private com.irurueta.geometry.estimators.PointCorrespondenceProjectiveTransformation2DRobustEstimator
Homography estimator relating both views.private com.irurueta.geometry.PinholeCameraIntrinsicParameters
Intrinsic parameters for the camera on the left view.private List<com.irurueta.geometry.Point2D>
List of matched 2D points in the left view.Listener to attend events generated by this instance.private boolean
Indicates whether this instance is locked while computing a solution.static final int
Minimum number of matched points required to find a solution.private com.irurueta.geometry.PinholeCameraIntrinsicParameters
Intrinsic parameters for the camera on the right view.private List<com.irurueta.geometry.Point2D>
List of matched 2D points in the right view.private List<com.irurueta.geometry.Point3D>
Best estimated triangulated points.private BitSet
Contains booleans indicating which of the best triangulated points are valid (i.e. lie in front of both estimated cameras) or not. -
Constructor Summary
ConstructorsConstructorDescriptionConstructor.PlanarBestFundamentalMatrixEstimatorAndReconstructor
(List<com.irurueta.geometry.Point2D> leftPoints, List<com.irurueta.geometry.Point2D> rightPoints, com.irurueta.geometry.PinholeCameraIntrinsicParameters leftIntrinsics, com.irurueta.geometry.PinholeCameraIntrinsicParameters rightIntrinsics) Constructor.PlanarBestFundamentalMatrixEstimatorAndReconstructor
(List<com.irurueta.geometry.Point2D> leftPoints, List<com.irurueta.geometry.Point2D> rightPoints, com.irurueta.geometry.PinholeCameraIntrinsicParameters leftIntrinsics, com.irurueta.geometry.PinholeCameraIntrinsicParameters rightIntrinsics, PlanarBestFundamentalMatrixEstimatorAndReconstructorListener listener) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
Ensures that inlier estimation is enabled on homography estimator.void
Estimates homography, the best fundamental matrix, their cameras and reconstructs matched points.Gets type of corrector to use to triangulate matched points using the corresponding essential matrix or null if no corrector needs to be used.com.irurueta.geometry.PinholeCamera
Gets best estimated camera for left view.com.irurueta.geometry.PinholeCamera
Gets best estimated camera for right view.Gets best estimated fundamental matrix.com.irurueta.geometry.ProjectiveTransformation2D
Gets estimated homography.double
Gets amount of confidence on homography estimation expressed as a value between 0.0 and 1.0 (which is equivalent to 100%).com.irurueta.algebra.Matrix
Gets covariance for estimated homography if available.com.irurueta.geometry.estimators.PointCorrespondenceProjectiveTransformation2DRobustEstimator
Gets internal homography estimator.int
Returns maximum allowed number of iterations for homography estimation.com.irurueta.numerical.robust.RobustEstimatorMethod
Returns method being used for homography robust estimation.com.irurueta.geometry.PinholeCameraIntrinsicParameters
Gets intrinsic parameters for the camera on the left view.List<com.irurueta.geometry.Point2D>
Gets list of matched 2D points in the left view.Gets listener to attend events generated by this instance.double[]
Returns quality scores corresponding to each pair of matched points.com.irurueta.geometry.PinholeCameraIntrinsicParameters
Gets intrinsic parameters for the camera on the right view.List<com.irurueta.geometry.Point2D>
Gets list of matched 2D points in the right view.List<com.irurueta.geometry.Point3D>
Gets best estimated triangulated points.Gets set containing booleans indicating which of the best triangulated points are valid (i.e. lie in front of both estimated cameras) or not.private void
internalSetLeftAndRightPoints
(List<com.irurueta.geometry.Point2D> leftPoints, List<com.irurueta.geometry.Point2D> rightPoints) Internal method that sets list of matched 2D points in the left and right views.boolean
Indicates whether homography covariance must be kept after estimation.boolean
Indicates whether result of homography estimation is refined.boolean
isLocked()
Indicates whether this instance is locked while computing a solution.boolean
isReady()
Indicates whether this instance is ready to start the estimation when all required data has been provided.void
setEssentialCameraEstimatorCorrectorType
(CorrectorType correctorType) Sets type of corrector to use to triangulate matched points using the corresponding essential matrix or null if no corrector needs to be used.void
setHomographyConfidence
(double confidence) Sets amount of confidence on homography estimation expressed as a value between 0.0 and 1.0 (which is equivalent to 100%).void
setHomographyCovarianceKept
(boolean keepCovariance) Specifies whether homography covariance must be kept after estimation.void
setHomographyEstimator
(com.irurueta.geometry.estimators.PointCorrespondenceProjectiveTransformation2DRobustEstimator homographyEstimator) Sets internal homography estimator.void
setHomographyMaxIterations
(int maxIterations) Sets maximum allowed number of iterations for homography estimation.void
setHomographyRefined
(boolean refineResult) Specifies whether homography estimation must be refined or not.void
setLeftAndRightPoints
(List<com.irurueta.geometry.Point2D> leftPoints, List<com.irurueta.geometry.Point2D> rightPoints) Sets lists of matched 2D points in the left and right views.void
setLeftIntrinsics
(com.irurueta.geometry.PinholeCameraIntrinsicParameters leftIntrinsics) Sets intrinsic parameters for the camera on the left view.void
setLeftPoints
(List<com.irurueta.geometry.Point2D> leftPoints) Sets list of matched 2D points in the left view.void
Sets listener to attend events generated by this instance.void
setQualityScores
(double[] qualityScore) Sets quality scores corresponding to each pair of matched points.void
setRightIntrinsics
(com.irurueta.geometry.PinholeCameraIntrinsicParameters rightIntrinsics) Sets intrinsic parameters for the camera on the right view.void
setRightPoints
(List<com.irurueta.geometry.Point2D> rightPoints) Sets list of matched 2D points in the right view.
-
Field Details
-
MINIMUM_SIZE
public static final int MINIMUM_SIZEMinimum number of matched points required to find a solution.- See Also:
-
leftPoints
List of matched 2D points in the left view. -
rightPoints
List of matched 2D points in the right view. -
leftIntrinsics
private com.irurueta.geometry.PinholeCameraIntrinsicParameters leftIntrinsicsIntrinsic parameters for the camera on the left view. -
rightIntrinsics
private com.irurueta.geometry.PinholeCameraIntrinsicParameters rightIntrinsicsIntrinsic parameters for the camera on the right view. -
listener
Listener to attend events generated by this instance. -
locked
private boolean lockedIndicates whether this instance is locked while computing a solution. -
homographyEstimator
private com.irurueta.geometry.estimators.PointCorrespondenceProjectiveTransformation2DRobustEstimator homographyEstimatorHomography estimator relating both views. -
essentialCameraEstimatorCorrectorType
Type of corrector to use to triangulate matched points using the corresponding essential matrix or null if no corrector needs to be used. -
homography
private com.irurueta.geometry.ProjectiveTransformation2D homographyEstimated homography. -
fundamentalMatrix
Best estimated fundamental matrix. -
triangulatedPoints
Best estimated triangulated points. -
validTriangulatedPoints
Contains booleans indicating which of the best triangulated points are valid (i.e. lie in front of both estimated cameras) or not. -
estimatedLeftCamera
private com.irurueta.geometry.PinholeCamera estimatedLeftCameraBest estimated camera for left view. -
estimatedRightCamera
private com.irurueta.geometry.PinholeCamera estimatedRightCameraBest estimated camera for right view.
-
-
Constructor Details
-
PlanarBestFundamentalMatrixEstimatorAndReconstructor
public PlanarBestFundamentalMatrixEstimatorAndReconstructor()Constructor. -
PlanarBestFundamentalMatrixEstimatorAndReconstructor
public PlanarBestFundamentalMatrixEstimatorAndReconstructor(List<com.irurueta.geometry.Point2D> leftPoints, List<com.irurueta.geometry.Point2D> rightPoints, com.irurueta.geometry.PinholeCameraIntrinsicParameters leftIntrinsics, com.irurueta.geometry.PinholeCameraIntrinsicParameters rightIntrinsics) Constructor.- Parameters:
leftPoints
- list of matched 2D points in the left view.rightPoints
- list of matched 2D points in the right view.leftIntrinsics
- intrinsic parameters for the camera on the left view.rightIntrinsics
- intrinsic parameters for the camera on the right view.- Throws:
IllegalArgumentException
- if provided list of matched points do not contain enough points or if they have different sizes.
-
PlanarBestFundamentalMatrixEstimatorAndReconstructor
public PlanarBestFundamentalMatrixEstimatorAndReconstructor(List<com.irurueta.geometry.Point2D> leftPoints, List<com.irurueta.geometry.Point2D> rightPoints, com.irurueta.geometry.PinholeCameraIntrinsicParameters leftIntrinsics, com.irurueta.geometry.PinholeCameraIntrinsicParameters rightIntrinsics, PlanarBestFundamentalMatrixEstimatorAndReconstructorListener listener) Constructor.- Parameters:
leftPoints
- list of matched 2D points in the left view.rightPoints
- list of matched 2D points in the right view.leftIntrinsics
- intrinsic parameters for the camera on the left view.rightIntrinsics
- intrinsic parameters for the camera on the right view.listener
- listener to be notified of events generated by this instance.- Throws:
IllegalArgumentException
- if provided list of matched points do not contain enough points or if they have different sizes.
-
-
Method Details
-
getLeftPoints
Gets list of matched 2D points in the left view.- Returns:
- list of matched 2D points in the left view.
-
setLeftPoints
public void setLeftPoints(List<com.irurueta.geometry.Point2D> leftPoints) throws com.irurueta.geometry.estimators.LockedException Sets list of matched 2D points in the left view.- Parameters:
leftPoints
- list of matched 2D points in the left view.- Throws:
com.irurueta.geometry.estimators.LockedException
- if this instance is locked.IllegalArgumentException
- if provided points do not have enough points.
-
getRightPoints
Gets list of matched 2D points in the right view.- Returns:
- list of matched 2D points in the right view.
-
setRightPoints
public void setRightPoints(List<com.irurueta.geometry.Point2D> rightPoints) throws com.irurueta.geometry.estimators.LockedException Sets list of matched 2D points in the right view.- Parameters:
rightPoints
- list of matched 2D points in the right view.- Throws:
com.irurueta.geometry.estimators.LockedException
- if this instance is locked.IllegalArgumentException
- if provided points do not have enough points.
-
setLeftAndRightPoints
public void setLeftAndRightPoints(List<com.irurueta.geometry.Point2D> leftPoints, List<com.irurueta.geometry.Point2D> rightPoints) throws com.irurueta.geometry.estimators.LockedException Sets lists of matched 2D points in the left and right views.- Parameters:
leftPoints
- list of matched 2D points in the left view.rightPoints
- list of matched 2D points in the right view.- Throws:
com.irurueta.geometry.estimators.LockedException
- if this instance is locked.IllegalArgumentException
- if provided points do not have enough points or lists have different sizes.
-
getLeftIntrinsics
public com.irurueta.geometry.PinholeCameraIntrinsicParameters getLeftIntrinsics()Gets intrinsic parameters for the camera on the left view.- Returns:
- intrinsic parameters for the camera on the left view.
-
setLeftIntrinsics
public void setLeftIntrinsics(com.irurueta.geometry.PinholeCameraIntrinsicParameters leftIntrinsics) throws com.irurueta.geometry.estimators.LockedException Sets intrinsic parameters for the camera on the left view.- Parameters:
leftIntrinsics
- intrinsic parameters for the camera on the left view.- Throws:
com.irurueta.geometry.estimators.LockedException
- if estimator is locked.
-
getRightIntrinsics
public com.irurueta.geometry.PinholeCameraIntrinsicParameters getRightIntrinsics()Gets intrinsic parameters for the camera on the right view.- Returns:
- intrinsic parameters for the camera on the right view.
-
setRightIntrinsics
public void setRightIntrinsics(com.irurueta.geometry.PinholeCameraIntrinsicParameters rightIntrinsics) throws com.irurueta.geometry.estimators.LockedException Sets intrinsic parameters for the camera on the right view.- Parameters:
rightIntrinsics
- intrinsic parameters for the camera on the right view.- Throws:
com.irurueta.geometry.estimators.LockedException
- if estimator is locked.
-
getHomographyEstimator
public com.irurueta.geometry.estimators.PointCorrespondenceProjectiveTransformation2DRobustEstimator getHomographyEstimator()Gets internal homography estimator.- Returns:
- internal homography estimator.
-
setHomographyEstimator
public void setHomographyEstimator(com.irurueta.geometry.estimators.PointCorrespondenceProjectiveTransformation2DRobustEstimator homographyEstimator) throws com.irurueta.geometry.estimators.LockedException Sets internal homography estimator.- Parameters:
homographyEstimator
- internal homography estimator.- Throws:
com.irurueta.geometry.estimators.LockedException
- if estimator is locked.NullPointerException
- if provided estimator is null.
-
getEssentialCameraEstimatorCorrectorType
Gets type of corrector to use to triangulate matched points using the corresponding essential matrix or null if no corrector needs to be used.- Returns:
- corrector to use for triangulation or null.
-
setEssentialCameraEstimatorCorrectorType
public void setEssentialCameraEstimatorCorrectorType(CorrectorType correctorType) throws com.irurueta.geometry.estimators.LockedException Sets type of corrector to use to triangulate matched points using the corresponding essential matrix or null if no corrector needs to be used.- Parameters:
correctorType
- corrector to use for triangulation or null.- Throws:
com.irurueta.geometry.estimators.LockedException
- if estimator is locked.
-
getHomographyConfidence
public double getHomographyConfidence()Gets amount of confidence on homography estimation expressed as a value between 0.0 and 1.0 (which is equivalent to 100%). The amount of confidence indicates the probability that the estimated result is correct. Usually this value will be close to 1.0, but not exactly 1.0.- Returns:
- amount of confidence as a value between 0.0 and 1.0.
-
setHomographyConfidence
public void setHomographyConfidence(double confidence) throws com.irurueta.geometry.estimators.LockedException Sets amount of confidence on homography estimation expressed as a value between 0.0 and 1.0 (which is equivalent to 100%). The amount of confidence indicates the probability that the estimated result is correct. Usually this value will be close to 1.0, but not exactly 1.0.- Parameters:
confidence
- confidence to be set as a value between 0.0 and 1.0.- Throws:
IllegalArgumentException
- if provided value is not between 0.0 and 1.0.com.irurueta.geometry.estimators.LockedException
- if estimator is locked.
-
getHomographyMaxIterations
public int getHomographyMaxIterations()Returns maximum allowed number of iterations for homography estimation.- Returns:
- maximum allowed number of iterations.
-
setHomographyMaxIterations
public void setHomographyMaxIterations(int maxIterations) throws com.irurueta.geometry.estimators.LockedException Sets maximum allowed number of iterations for homography estimation.- Parameters:
maxIterations
- maximum allowed number of iterations.- Throws:
IllegalArgumentException
- if provided value is less than 1.com.irurueta.geometry.estimators.LockedException
- if estimator is locked.
-
isHomographyRefined
public boolean isHomographyRefined()Indicates whether result of homography estimation is refined.- Returns:
- true to refine homography result, false to simply use result found by robust estimation without further refining.
-
setHomographyRefined
public void setHomographyRefined(boolean refineResult) throws com.irurueta.geometry.estimators.LockedException Specifies whether homography estimation must be refined or not.- Parameters:
refineResult
- true to refine homography result, false to simply use result found by robust estimator without further refining.- Throws:
com.irurueta.geometry.estimators.LockedException
- if estimator is locked.
-
isHomographyCovarianceKept
public boolean isHomographyCovarianceKept()Indicates whether homography covariance must be kept after estimation. This setting is only taken into account if homography is refined.- Returns:
- true if homography covariance must be kept after estimation, false otherwise.
-
setHomographyCovarianceKept
public void setHomographyCovarianceKept(boolean keepCovariance) throws com.irurueta.geometry.estimators.LockedException Specifies whether homography covariance must be kept after estimation. This setting is only taken into account if homography is refined.- Parameters:
keepCovariance
- true if homography covariance must be kept after estimation, false otherwise.- Throws:
com.irurueta.geometry.estimators.LockedException
- if estimator is locked.
-
getHomographyCovariance
public com.irurueta.algebra.Matrix getHomographyCovariance()Gets covariance for estimated homography if available. This is only available when homography has been refined and covariance is kept.- Returns:
- estimated homography covariance or null.
-
getHomographyMethod
public com.irurueta.numerical.robust.RobustEstimatorMethod getHomographyMethod()Returns method being used for homography robust estimation.- Returns:
- method being used for homography robust estimation.
-
getQualityScores
public double[] getQualityScores()Returns quality scores corresponding to each pair of matched points. This is used for homography estimation. The larger the score value the better the quality of the matching.- Returns:
- quality scores for each pair of matched points.
-
setQualityScores
public void setQualityScores(double[] qualityScore) throws com.irurueta.geometry.estimators.LockedException Sets quality scores corresponding to each pair of matched points. This is used for homography estimation. The larger the score value the better the quality of the matching.- Parameters:
qualityScore
- quality scores corresponding to eac pair of matched points.- Throws:
com.irurueta.geometry.estimators.LockedException
- if estimator is locked.IllegalArgumentException
- if provided quality scores length is smaller than minimum required size (4 points).
-
getListener
Gets listener to attend events generated by this instance.- Returns:
- listener to attend events generated by this instance.
-
setListener
Sets listener to attend events generated by this instance.- Parameters:
listener
- listener to attend events generated by this instance.
-
isLocked
public boolean isLocked()Indicates whether this instance is locked while computing a solution.- Returns:
- true if this instance is locked, false otherwise.
-
isReady
public boolean isReady()Indicates whether this instance is ready to start the estimation when all required data has been provided.- Returns:
- true if this instance is ready, false otherwise.
-
getHomography
public com.irurueta.geometry.ProjectiveTransformation2D getHomography()Gets estimated homography.- Returns:
- estimated homography.
-
getFundamentalMatrix
Gets best estimated fundamental matrix.- Returns:
- best estimated fundamental matrix.
-
getTriangulatedPoints
Gets best estimated triangulated points.- Returns:
- best estimated triangulated points.
-
getValidTriangulatedPoints
Gets set containing booleans indicating which of the best triangulated points are valid (i.e. lie in front of both estimated cameras) or not.- Returns:
- set indicating which of the best triangulated points are valid.
-
getEstimatedLeftCamera
public com.irurueta.geometry.PinholeCamera getEstimatedLeftCamera()Gets best estimated camera for left view.- Returns:
- best estimated camera for left view.
-
getEstimatedRightCamera
public com.irurueta.geometry.PinholeCamera getEstimatedRightCamera()Gets best estimated camera for right view.- Returns:
- best estimated camera for right view.
-
estimateAndReconstruct
public void estimateAndReconstruct() throws com.irurueta.geometry.estimators.LockedException, com.irurueta.geometry.estimators.NotReadyException, FundamentalMatrixEstimatorExceptionEstimates homography, the best fundamental matrix, their cameras and reconstructs matched points.- Throws:
com.irurueta.geometry.estimators.LockedException
- if estimator is locked.com.irurueta.geometry.estimators.NotReadyException
- if estimator is not ready because required data is missing.FundamentalMatrixEstimatorException
- if something fails, typically due to numerical instabilities.
-
internalSetLeftAndRightPoints
private void internalSetLeftAndRightPoints(List<com.irurueta.geometry.Point2D> leftPoints, List<com.irurueta.geometry.Point2D> rightPoints) Internal method that sets list of matched 2D points in the left and right views.- Parameters:
leftPoints
- list of matched 2D points in the left view.rightPoints
- list of matched 2D points in the right view.- Throws:
IllegalArgumentException
- if provided points do not have enough points or lists have different sizes.
-
enableHomographyInliersEstimation
private void enableHomographyInliersEstimation()Ensures that inlier estimation is enabled on homography estimator.
-