public class CameraCalibrationUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
FIX_ASPECT_RATIO |
static int |
FIX_PRINCIPAL_POINT |
static int |
FIX_RADIAL_DISTORTION_COEFFICENTS |
static int |
FIX_TANGENTIAL_DISTORTION_COEFFICENTS |
static int |
FIX_TILT |
static double |
sigmaThresholdForRejectingOutliers |
Constructor and Description |
---|
CameraCalibrationUtils() |
Modifier and Type | Method and Description |
---|---|
static double |
computeBestCameraParameters(double[][][] testPattern3dPoints,
double[][][] testPatternImagePoints,
double[][][] modeledImagePoints,
java.util.List<java.lang.Integer> outlierPointList,
double[] parameters)
Computes the best, in a least squared error sense, set of camera parameters that transform
the given test pattern 3D coordinates to the corresponding 2D image points.
|
static double |
computeBestCameraParameters(double[][][] testPattern3dPoints,
double[][][] testPatternImagePoints,
double[][][] modeledImagePoints,
java.util.List<java.lang.Integer> outlierPointList,
double[] parameters,
int flags)
Computes the best, in a least squared error sense, set of camera parameters that transform
the given test pattern 3D coordinates to the corresponding 2D image points.
|
static double |
computeDrmsError(java.util.List<double[]> residuals)
Computes the Distance Root-Mean-Squared (DRMS) error for a given set of 2D errors
|
static Mat |
computeRectificationMatrix(Mat transformFromMachToPhyCamRefFrame,
Mat vectorFromMachToPhyCamInMachRefFrame,
Mat transformFromMachToVirCamRefFrame,
Mat vectorFromMachToVirCamInMachRefFrame,
double primaryZ)
Computes the rectification matrix that converts normalized physical camera coordinates to the
virtual camera coordinates
|
static java.util.List<double[]> |
computeResidualErrors(double[][][] actual2DPoints,
double[][][] modeled2DPoints)
Computes the 2D error between the actual image points and the modeled image points
|
static java.util.List<double[]> |
computeResidualErrors(double[][][] actual2DPoints,
double[][][] modeled2DPoints,
java.util.ArrayList<java.lang.Integer> outlierList)
Computes the 2D error between the actual image points and the modeled image points
|
static java.util.List<double[]> |
computeResidualErrors(double[][][] actual2DPoints,
double[][][] modeled2DPoints,
java.lang.Integer heightIndex)
Computes the 2D error between the actual image points and the modeled image points
|
static java.util.List<double[]> |
computeResidualErrors(double[][][] actual2DPoints,
double[][][] modeled2DPoints,
java.lang.Integer heightIndex,
java.util.ArrayList<java.lang.Integer> outlierList)
Computes the 2D error between the actual image points and the modeled image points
|
static Mat |
computeVirtualCameraMatrix(Mat physicalCameraMatrix,
Mat distortionCoefficients,
Mat rectification,
Size phyCamSize,
Size virCamSize,
double alpha,
boolean keepPrincipalPoint)
Computes the virtual camera matrix.
|
static Mat |
computeVirtualCameraMatrix(Mat physicalCameraMatrix,
Mat distortionCoefficients,
Mat rectification,
Size phyCamSize,
Size virCamSize,
double alpha,
Mat principalPoint)
Computes the virtual camera matrix.
|
static Mat |
generateErrorImage(Size size,
int testPatternIndex,
double[][][] actual2DPoints,
double[][][] modeled2DPoints,
java.util.ArrayList<java.lang.Integer> outlierList)
Generates a heat map of the residual errors between the actual image points and the modeled
image points.
|
public static final int FIX_ASPECT_RATIO
public static final int FIX_PRINCIPAL_POINT
public static final int FIX_RADIAL_DISTORTION_COEFFICENTS
public static final int FIX_TILT
public static final int FIX_TANGENTIAL_DISTORTION_COEFFICENTS
public static final double sigmaThresholdForRejectingOutliers
public static double computeBestCameraParameters(double[][][] testPattern3dPoints, double[][][] testPatternImagePoints, double[][][] modeledImagePoints, java.util.List<java.lang.Integer> outlierPointList, double[] parameters) throws java.lang.Exception
testPattern3dPoints
- - a numberOfTestPatterns x numberOfPointsPerTestPattern x 3 array
containing the 3D machine coordinates at which the corresponding point in
testPatternImagePoints was collected.testPatternImagePoints
- - a numberOfTestPatterns x numberOfPointsPerTestPattern x 2
array containing the 2D image coordinates of the corresponding point in
testPattern3dPoints.modeledImagePoints
- - a numberOfTestPatterns x numberOfPointsPerTestPattern x 2 array
that, upon return of this method, will contain the 2D modeled image coordinates of the
corresponding points in testPattern3dPoints.outlierPointList
- - an output list of indices to points that were excluded from the
parameter estimation due to being possible outliers.parameters
- - a 13+2*numberOfTestPatterns element array containing the camera
parameters to be estimated in the following order: fx, fy, cx, cy, k1, k2, p1, p2, k3,
Rx, Ry, Rz, cam_z, cam_x[0], cam_y[0], ... cam_x[numberOfTestPatterns-1],
cam_y[numberOfTestPatterns-1]. Where fx, fy, cx, and cy are the intrinsic camera
matrix components; k1, k2, p1, p2, and k3 are the intrinsic camera lens distortion
coefficients; Rx, Ry, and Rz are the extrinsic camera rotation vector components;
cam_z is the camera Z machine coordinate; and cam_x[0], cam_y[0], ...
cam_x[numberOfTestPatterns-1], and cam_y[numberOfTestPatterns-1] are the camera X/Y
machine coordinates for each test pattern. This array needs to be initialized with
approximately correct values prior to calling this method and upon return of this
method will contain the best fit camera parameters.java.lang.Exception
public static double computeBestCameraParameters(double[][][] testPattern3dPoints, double[][][] testPatternImagePoints, double[][][] modeledImagePoints, java.util.List<java.lang.Integer> outlierPointList, double[] parameters, int flags) throws java.lang.Exception
testPattern3dPoints
- - a numberOfTestPatterns x numberOfPointsPerTestPattern x 3 array
containing the 3D machine coordinates at which the corresponding point in
testPatternImagePoints was collected.testPatternImagePoints
- - a numberOfTestPatterns x numberOfPointsPerTestPattern x 2
array containing the 2D image coordinates of the corresponding point in
testPattern3dPoints.modeledImagePoints
- - a numberOfTestPatterns x numberOfPointsPerTestPattern x 2 array
that, upon return of this method, will contain the 2D modeled image coordinates of the
corresponding points in testPattern3dPoints.outlierPointList
- - an output list of indices to points that were excluded from the
parameter estimation due to being possible outliers.parameters
- - a 13+2*numberOfTestPatterns element array containing the camera
parameters to be estimated in the following order: fx, fy, cx, cy, k1, k2, p1, p2, k3,
Rx, Ry, Rz, cam_z, cam_x[0], cam_y[0], ... cam_x[numberOfTestPatterns-1],
cam_y[numberOfTestPatterns-1]. Where fx, fy, cx, and cy are the intrinsic camera
matrix components; k1, k2, p1, p2, and k3 are the intrinsic camera lens distortion
coefficients; Rx, Ry, and Rz are the extrinsic camera rotation vector components;
cam_z is the camera Z machine coordinate; and cam_x[0], cam_y[0], ...
cam_x[numberOfTestPatterns-1], and cam_y[numberOfTestPatterns-1] are the camera X/Y
machine coordinates for each test pattern. This array needs to be initialized with
approximately correct values prior to calling this method and upon return of this
method will contain the best fit camera parameters.flags
- - Flags used to force certain parameters be retained from the initial starting
values. Can be one or more of the follow added/or'ed together: FIX_ASPECT_RATIO,
FIX_CENTER_POINT, FIX_RADIAL_DISTORTION_COEFFICENTS, FIX_TILT,
FIX_TANGENTIAL_DISTORTION_COEFFICENTS.java.lang.Exception
public static Mat computeRectificationMatrix(Mat transformFromMachToPhyCamRefFrame, Mat vectorFromMachToPhyCamInMachRefFrame, Mat transformFromMachToVirCamRefFrame, Mat vectorFromMachToVirCamInMachRefFrame, double primaryZ)
transformFromMachToPhyCamRefFrame
- - the 3x3 rotation matrix that converts vector
components from the machine coordinate system to the physical camera coordinate systemvectorFromMachToPhyCamInMachRefFrame
- - the 3x1 vector from the machine origin to the
physical camera origin with components represented in the machine coordinate systemtransformFromMachToVirCamRefFrame
- - the 3x3 rotation matrix that converts vector
components from the machine coordinate system to the virtual camera coordinate systemvectorFromMachToVirCamInMachRefFrame
- - the 3x1 vector from the machine origin to the
virtual camera origin with components represented in the machine coordinate systemprimaryZ
- - the machine Z coordinate, in millimeters, that is used as the default
imaging heightpublic static Mat computeVirtualCameraMatrix(Mat physicalCameraMatrix, Mat distortionCoefficients, Mat rectification, Size phyCamSize, Size virCamSize, double alpha, boolean keepPrincipalPoint)
physicalCameraMatrix
- - the physical camera's intrinsic matrixdistortionCoefficients
- - the physical camera's lens distortion coefficientsrectification
- - the rectification matrix that takes the physical camera points to the
virtual camera pointssize
- - the physical camera's image sizealpha
- - a free scaling parameter in the range 0 to 1 inclusive. A value of a zero
ensures only valid image pixels are displayed but may result in the loss of some valid
pixels around the edge of the image. A value of one ensure all valid pixels are
displayed but that may result in some invalid (usually black) pixels being displayed
around the edge of the image.keepPrincipalPoint
- - if set true, the virtual camera's principal point is set to match
that of the physical camera's principal pointpublic static Mat computeVirtualCameraMatrix(Mat physicalCameraMatrix, Mat distortionCoefficients, Mat rectification, Size phyCamSize, Size virCamSize, double alpha, Mat principalPoint)
physicalCameraMatrix
- - the physical camera's intrinsic matrixdistortionCoefficients
- - the physical camera's lens distortion coefficientsrectification
- - the rectification matrix that takes the physical camera points to the
virtual camera pointsphyCamSize
- - the physical camera's image sizevirCamSize
- - (output) the virtual camera's image sizealpha
- - a free scaling parameter in the range 0 to 1 inclusive. A value of a zero
ensures only valid image pixels are displayed but may result in the loss of some valid
pixels around the edge of the image. A value of one ensure all valid pixels are
displayed but that may result in some invalid (usually black) pixels being displayed
around the edge of the image.principalPoint
- - a 3x1 matrix containing the point in physical camera coordinates of
the desired principal point of the virtual camera, if null, the principal point will
be computed so as to maximize the valid pixels in the resulting imagepublic static java.util.List<double[]> computeResidualErrors(double[][][] actual2DPoints, double[][][] modeled2DPoints)
actual2DPoints
- - the actual image pointsmodeled2DPoints
- - the modeled image pointspublic static java.util.List<double[]> computeResidualErrors(double[][][] actual2DPoints, double[][][] modeled2DPoints, java.util.ArrayList<java.lang.Integer> outlierList)
actual2DPoints
- - the actual image pointsmodeled2DPoints
- - the modeled image pointsoutlierList
- - a list of outlier points to exclude, set to null to not exclude any
pointspublic static java.util.List<double[]> computeResidualErrors(double[][][] actual2DPoints, double[][][] modeled2DPoints, java.lang.Integer heightIndex)
actual2DPoints
- - the actual image pointsmodeled2DPoints
- - the modeled image pointsheightIndex
- - index to select which calibration height to compute the residual
errors, set to null to compute over all heightspublic static java.util.List<double[]> computeResidualErrors(double[][][] actual2DPoints, double[][][] modeled2DPoints, java.lang.Integer heightIndex, java.util.ArrayList<java.lang.Integer> outlierList)
actual2DPoints
- - the actual image pointsmodeled2DPoints
- - the modeled image pointsheightIndex
- - index to select which calibration height to compute the residual
errors, set to null to compute over all heightsoutlierList
- - a list of outlier points to exclude, set to null to not exclude any
pointspublic static double computeDrmsError(java.util.List<double[]> residuals)
residuals
- - the errorspublic static Mat generateErrorImage(Size size, int testPatternIndex, double[][][] actual2DPoints, double[][][] modeled2DPoints, java.util.ArrayList<java.lang.Integer> outlierList)
size
- - the image sizetestPatternIndex
- - selects which calibration height for which the image is generatedactual2DPoints
- - the actual 2D image pointsmodeled2DPoints
- - the modeled 2D image pointsoutlierList
- - a list of outlier points to exclude from the image, set to null to not
exclude any points