Class HomographyDirectLinearTransform
- java.lang.Object
-
- boofcv.alg.geo.h.HomographyDirectLinearTransform
-
public class HomographyDirectLinearTransform extends java.lang.ObjectUsing linear algebra it computes a planar homography matrix using 2D points, 3D points, or conics. Typically used as an initial estimate for a non-linear optimization. See [1] for 2D and 3D points, and [2] for conics.
The algorithm works by solving the equation below:
hat(x2)*H*x1 = 0
where hat(x) is the skew symmetric cross product matrix. To solve this equation is is reformatted into A*Hs=0 using the Kronecker product and the null space solved for.The conic algorithm specifies a constraint using a pair of conics. A minimum of 3 conics are required for a unique solution using this linear method [2]. If all possible pairs are used then the growth is O(N^2) instead linear set of pairs are added which has O(N) growth by adding adjacent conics as pairs. This behavior can be toggled.
[1] Chapter 4, "Multiple View Geometry in Computer Vision" 2nd Ed. but uses normalization from "An Invitation to 3-D Vision" 2004.
[2] Kannala, Juho, Mikko Salo, and Janne Heikkilä. "Algorithms for Computing a Planar Homography from Conics in Correspondence." BMVC. 2006.
-
-
Field Summary
Fields Modifier and Type Field Description protected org.ejml.data.DMatrixRMajAprotected NormalizationPoint2DN1protected NormalizationPoint2DN2protected org.ejml.interfaces.SolveNullSpace<org.ejml.data.DMatrixRMaj>solverNullspace
-
Constructor Summary
Constructors Constructor Description HomographyDirectLinearTransform(boolean normalizeInput)Configure homography calculation
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected intaddConicPairConstraints(AssociatedPairConic a, AssociatedPairConic b, org.ejml.data.DMatrixRMaj A, int rowA)Add constraint for a pair of conicsprotected intaddConics(java.util.List<AssociatedPairConic> points, org.ejml.data.DMatrixRMaj A, int rows)Adds the 9x9 matrix constraint for each pair of conics.protected intaddPoints2D(java.util.List<AssociatedPair> points, org.ejml.data.DMatrixRMaj A, int rows)protected intaddPoints3D(java.util.List<AssociatedPair3D> points, org.ejml.data.DMatrixRMaj A, int rows)protected booleancomputeH(org.ejml.data.DMatrixRMaj A, org.ejml.data.DMatrixRMaj H)Computes the SVD of A and extracts the homography matrix from its null spaceorg.ejml.interfaces.SolveNullSpace<org.ejml.data.DMatrixRMaj>getSolverNullspace()booleanisExhaustiveConics()booleanisNormalize()booleanprocess(java.util.List<AssociatedPair> points2D, java.util.List<AssociatedPair3D> points3D, java.util.List<AssociatedPairConic> conics, org.ejml.data.DMatrixRMaj foundH)More versatile process function.booleanprocess(java.util.List<AssociatedPair> points, org.ejml.data.DMatrixRMaj foundH)Computes the homography matrix given a set of observed points in two images.voidsetExhaustiveConics(boolean exhaustiveConics)static voidundoNormalizationH(org.ejml.data.DMatrixRMaj M, NormalizationPoint2D N1, NormalizationPoint2D N2)Undoes normalization for a homography matrix.
-
-
-
Field Detail
-
A
protected org.ejml.data.DMatrixRMaj A
-
solverNullspace
protected org.ejml.interfaces.SolveNullSpace<org.ejml.data.DMatrixRMaj> solverNullspace
-
N1
protected NormalizationPoint2D N1
-
N2
protected NormalizationPoint2D N2
-
-
Method Detail
-
process
public boolean process(java.util.List<AssociatedPair> points, org.ejml.data.DMatrixRMaj foundH)
Computes the homography matrix given a set of observed points in two images. A set of
AssociatedPairis passed in. The computed homography 'H' is found such that the attributes 'p1' and 'p2' inAssociatedPairrefers to x1 and x2, respectively, in the equation below:
x2 = H*x1- Parameters:
points- A set of observed image points that are generated from a planar object. Minimum of 4 pairs required.foundH- Output: Storage for the found solution. 3x3 matrix.- Returns:
- True if successful. False if it failed.
-
process
public boolean process(@Nullable java.util.List<AssociatedPair> points2D, @Nullable java.util.List<AssociatedPair3D> points3D, @Nullable java.util.List<AssociatedPairConic> conics, org.ejml.data.DMatrixRMaj foundH)More versatile process function. Lets any of the supporting data structures be passed in.- Parameters:
points2D- List of 2D point associations. Can be null.points3D- List of 3D point or 2D line associations. Can be null.conics- List of conics. Can be nullfoundH- (Output) The estimated homography- Returns:
- True if successful. False if it failed.
-
computeH
protected boolean computeH(org.ejml.data.DMatrixRMaj A, org.ejml.data.DMatrixRMaj H)Computes the SVD of A and extracts the homography matrix from its null space
-
undoNormalizationH
public static void undoNormalizationH(org.ejml.data.DMatrixRMaj M, NormalizationPoint2D N1, NormalizationPoint2D N2)Undoes normalization for a homography matrix.
-
addPoints2D
protected int addPoints2D(java.util.List<AssociatedPair> points, org.ejml.data.DMatrixRMaj A, int rows)
-
addPoints3D
protected int addPoints3D(java.util.List<AssociatedPair3D> points, org.ejml.data.DMatrixRMaj A, int rows)
-
addConics
protected int addConics(java.util.List<AssociatedPairConic> points, org.ejml.data.DMatrixRMaj A, int rows)
Adds the 9x9 matrix constraint for each pair of conics. To avoid O(N^2) growth the default option only adds O(N) pairs. if only conics are used then a minimum of 3 is required. See [2].
inv(C[1]')*(C[2]')*H - H*invC[1]*C[2] == 0 Note: x' = H*x. C' is conic from the same view as x' and C from x. It can be shown that C = H^T*C'*H
-
addConicPairConstraints
protected int addConicPairConstraints(AssociatedPairConic a, AssociatedPairConic b, org.ejml.data.DMatrixRMaj A, int rowA)
Add constraint for a pair of conics
-
getSolverNullspace
public org.ejml.interfaces.SolveNullSpace<org.ejml.data.DMatrixRMaj> getSolverNullspace()
-
isNormalize
public boolean isNormalize()
-
isExhaustiveConics
public boolean isExhaustiveConics()
-
setExhaustiveConics
public void setExhaustiveConics(boolean exhaustiveConics)
-
-