Package paletai.mapping
Class MathHomography
java.lang.Object
paletai.mapping.MathHomography
A class for handling homography calculations and matrix operations.
Provides methods for calculating homography matrices between two planes,
matrix inversion, transposition, and conversion to Processing's PMatrix3D format.
This class implements the mathematical backbone for perspective transformations used in video mapping, including Gauss-Jordan elimination for matrix solving.
Key features:
- Homography matrix calculation from point correspondences
- Matrix inversion and transposition operations
- Gauss-Jordan elimination for linear systems
- Conversion to Processing's PMatrix3D format
- Support for both normalized and raw coordinate systems
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a MathHomography object initialized with an identity matrix. -
Method Summary
Modifier and TypeMethodDescriptionfloat[][]calculateHomography(processing.core.PVector[] xy, processing.core.PVector[] uv) Calculates the homography matrix between two sets of 4 points (xy to uv) using raw coordinates (not normalized).float[][]calculateHomography(processing.core.PVector[] xy, processing.core.PVector[] uv, int w, int h) Calculates the homography matrix between two sets of 4 points (xy to uv), with coordinates normalized by width and height.float[][]copyMatrix(float[][] m) Creates a deep copy of a matrix.float[][]GaussJordan(float[][] m) Performs Gauss-Jordan elimination on a matrix.processing.core.PMatrix3DgetMatrix(float[][] hinv) Converts a 3x3 homography matrix to a Processing PMatrix3D.processing.core.PMatrix3DgetMatrixInOut(processing.core.PVector[] xy, processing.core.PVector[] uv) Calculates and returns the inverse homography matrix as PMatrix3D.float[][]invertMatrix(float[][] m) Calculates the inverse of a matrix using Gauss-Jordan elimination.float[][]transpose(float[][] in) Transposes a matrix by swapping rows and columns.
-
Constructor Details
-
MathHomography
public MathHomography()Constructs a MathHomography object initialized with an identity matrix. The identity matrix represents no transformation when applied.
-
-
Method Details
-
calculateHomography
public float[][] calculateHomography(processing.core.PVector[] xy, processing.core.PVector[] uv, int w, int h) Calculates the homography matrix between two sets of 4 points (xy to uv), with coordinates normalized by width and height. Uses the direct linear transformation (DLT) algorithm to compute the perspective transformation between two planes.- Parameters:
xy- Array of 4 source points (PVector)uv- Array of 4 destination points (PVector)w- Width used for coordinate normalizationh- Height used for coordinate normalization- Returns:
- 3x3 homography matrix as float[][]
- See Also:
-
calculateHomography
public float[][] calculateHomography(processing.core.PVector[] xy, processing.core.PVector[] uv) Calculates the homography matrix between two sets of 4 points (xy to uv) using raw coordinates (not normalized). Uses the direct linear transformation (DLT) algorithm with raw pixel coordinates.- Parameters:
xy- Array of 4 source points (PVector)uv- Array of 4 destination points (PVector)- Returns:
- 3x3 homography matrix as float[][]
- See Also:
-
GaussJordan
public float[][] GaussJordan(float[][] m) Performs Gauss-Jordan elimination on a matrix. Transforms the input matrix into reduced row echelon form (RREF) through a series of row operations including pivoting and normalization.- Parameters:
m- Input matrix to be processed- Returns:
- The matrix in reduced row echelon form
- See Also:
-
copyMatrix
public float[][] copyMatrix(float[][] m) Creates a deep copy of a matrix. Allocates new memory and copies all values from the source matrix.- Parameters:
m- Matrix to be copied- Returns:
- A new matrix with identical values
-
invertMatrix
public float[][] invertMatrix(float[][] m) Calculates the inverse of a matrix using Gauss-Jordan elimination. Appends an identity matrix to the input, performs elimination, and extracts the inverse from the resulting matrix.- Parameters:
m- The matrix to invert (must be square)- Returns:
- The inverse matrix
- See Also:
-
transpose
public float[][] transpose(float[][] in) Transposes a matrix by swapping rows and columns. Creates a new matrix where element [i][j] becomes element [j][i].- Parameters:
in- The matrix to transpose- Returns:
- The transposed matrix
-
getMatrix
public processing.core.PMatrix3D getMatrix(float[][] hinv) Converts a 3x3 homography matrix to a Processing PMatrix3D. Embeds the 3x3 matrix into a 4x4 matrix suitable for OpenGL transformations.- Parameters:
hinv- The 3x3 homography matrix- Returns:
- PMatrix3D representation of the homography
- See Also:
-
getMatrixInOut
public processing.core.PMatrix3D getMatrixInOut(processing.core.PVector[] xy, processing.core.PVector[] uv) Calculates and returns the inverse homography matrix as PMatrix3D. This is useful for OpenGL coordinate transformations where the inverse matrix is typically required for proper perspective correction.- Parameters:
xy- Array of 4 source pointsuv- Array of 4 destination points- Returns:
- PMatrix3D representing the inverse homography
- See Also:
-