java.lang.Object
imagingbook.calibration.zhang.Camera

public class Camera extends Object
A camera model with parameters as specified in Zhang's paper.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Camera(double[] s)
    Creates a standard camera from a vector of intrinsic parameters
    Camera(double f, double uc, double vc)
    Creates a simple pinhole camera (with no distortion whatsoever).
    Camera(double alpha, double beta, double gamma, double uc, double vc, double k0, double k1)
     
    Camera(RealMatrix A, double[] K)
    Creates a standard camera from a transformation matrix and a vector of lens distortion coefficients.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    D(double r)
    Radial distortion function, to be applied in the form
    Returns a copy of the camera's inner transformation matrix with contents
    double
    Returns the camera's alpha value.
    double
    Returns the camera's beta value.
    double
    Returns the camera's gamma value.
    Returns the homography for the given view as a 3 x 3 matrix.
    Returns the inverse of the camera intrinsic matrix A as a 3x3 matrix (without the last row {0,0,1}).
    double[]
    Returns the camera's lens distortion coefficients.
    double[]
    Returns the camera's inner parameters as a vector (alpha, beta, gamma, uc, vc, k0, k1).
    double
    Returns the camera's uc value.
    double
    Returns the camera's vc value.
    double[]
    mapToSensorPlane(double[] xyd)
    Maps from the ideal projection plane to sensor coordinates, using the camera's intrinsic parameters.
    double[]
    project(ViewTransform view, double[] XYZ)
    Projects the given 3D point onto the sensor plane of this camera for the provided extrinsic view parameters.
    double[]
    Projects the X/Y world point (in the Z = 0 plane) to image coordinates under the given camera view (extrinsic transformation parameters).
    Projects the X/Y world points (all in the Z = 0 plane) to image coordinates under the given camera view (extrinsic transformation parameters).
    double[]
    projectNormalized(ViewTransform view, double[] XYZ)
    Projects the given 3D point to ideal projection coordinates for the provided extrinsic view parameters.
    double[]
    Projects the given 3D point to ideal projection coordinates for the provided extrinsic view parameters.
     
    double
    unwarp(double R)
    Inverse radial distortion function.
    double[]
    unwarp(double[] xyd)
    Applies inverse radial distortion to a given point in the ideal image plane.
    double
    warp(double r)
     
    double[]
    warp(double[] xy)
    Applies radial distortion to a point in the ideal 2D projection.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Camera

      public Camera(double alpha, double beta, double gamma, double uc, double vc, double k0, double k1)
    • Camera

      public Camera(double[] s)
      Creates a standard camera from a vector of intrinsic parameters
      Parameters:
      s - a vector of intrinsic camera parameters (alpha, beta, gamma, uc, vc, k0, k1).
    • Camera

      public Camera(RealMatrix A, double[] K)
      Creates a standard camera from a transformation matrix and a vector of lens distortion coefficients.
      Parameters:
      A - the (min.) 2 x 3 matrix holding the intrinsic camera parameters
      K - the radial distortion coefficients k0, k1, ... (may be null)
    • Camera

      public Camera(double f, double uc, double vc)
      Creates a simple pinhole camera (with no distortion whatsoever).
      Parameters:
      f - the camera's focal length (in pixel units).
      uc - the x-position of the optical axis intersecting the image plane (in pixel units)
      vc - the y-position of the optical axis intersecting the image plane (in pixel units)
  • Method Details

    • project

      public double[] project(ViewTransform view, Pnt2d P)
      Projects the X/Y world point (in the Z = 0 plane) to image coordinates under the given camera view (extrinsic transformation parameters).
      Parameters:
      view - the extrinsic transformation parameters
      P - a single X/Y world point (with Z = 0)
      Returns:
      the projected 2D image coordinates
    • project

      public Pnt2d[] project(ViewTransform view, Pnt2d[] PP)
      Projects the X/Y world points (all in the Z = 0 plane) to image coordinates under the given camera view (extrinsic transformation parameters).
      Parameters:
      view - the extrinsic transformation parameters
      PP - a set of X/Y world points (with Z = 0)
      Returns:
      the projected 2D image coordinates
    • project

      public double[] project(ViewTransform view, double[] XYZ)
      Projects the given 3D point onto the sensor plane of this camera for the provided extrinsic view parameters.
      Parameters:
      view - the extrinsic camera (view) parameters
      XYZ - a point in 3D world coordinates
      Returns:
      the 2D sensor coordinates of the projected point
    • projectNormalized

      public double[] projectNormalized(ViewTransform view, Pnt2d P)
      Projects the given 3D point to ideal projection coordinates for the provided extrinsic view parameters. The world point is specified as a 2D coordinate in the Z = 0 plane.
      Parameters:
      view - the extrinsic camera (view) parameters
      P - a point in 3D world coordinates (Z = 0)
      Returns:
      the 2D ideal projection
    • projectNormalized

      public double[] projectNormalized(ViewTransform view, double[] XYZ)
      Projects the given 3D point to ideal projection coordinates for the provided extrinsic view parameters.
      Parameters:
      view - the extrinsic camera (view) parameters
      XYZ - a point in 3D world coordinates
      Returns:
      the 2D ideal projection
    • warp

      public double warp(double r)
    • warp

      public double[] warp(double[] xy)
      Applies radial distortion to a point in the ideal 2D projection.
      Parameters:
      xy - a 2D point in the ideal projection
      Returns:
      the lens-distorted position in the ideal projection
    • unwarp

      public double unwarp(double R)
      Inverse radial distortion function. Finds the original (undistorted) radius r from the distorted radius R, both measured from the center = (0,0) of the ideal projection. Finds r as the root of the polynomial
      p(r) = - R + r + k0 * r^3 + k1 * r^5,
      where R is constant, by using a Newton-Raphson solver.
      Parameters:
      R - the distorted radius
      Returns:
      the undistorted radius
    • unwarp

      public double[] unwarp(double[] xyd)
      Applies inverse radial distortion to a given point in the ideal image plane.
      Parameters:
      xyd - a distorted 2D point in the ideal image plane
      Returns:
      the undistorted point
    • D

      public double D(double r)
      Radial distortion function, to be applied in the form
      r' = r * (1 + D(r))
      to points in the ideal projection plane. Distortion coefficients k0, k1 are a property of the enclosing Camera.
      Parameters:
      r - the original radius of a point in the ideal projection plane
      Returns:
      the pos/neg deviation for the given radius
    • mapToSensorPlane

      public double[] mapToSensorPlane(double[] xyd)
      Maps from the ideal projection plane to sensor coordinates, using the camera's intrinsic parameters.
      Parameters:
      xyd - a 2D point on the ideal projection plane
      Returns:
      the resulting 2D sensor coordinate
    • getParameterVector

      public double[] getParameterVector()
      Returns the camera's inner parameters as a vector (alpha, beta, gamma, uc, vc, k0, k1).
      Returns:
      the camera's inner parameters
    • getAlpha

      public double getAlpha()
      Returns the camera's alpha value.
      Returns:
      alpha
    • getBeta

      public double getBeta()
      Returns the camera's beta value.
      Returns:
      beta
    • getGamma

      public double getGamma()
      Returns the camera's gamma value.
      Returns:
      gamma
    • getUc

      public double getUc()
      Returns the camera's uc value.
      Returns:
      uc
    • getVc

      public double getVc()
      Returns the camera's vc value.
      Returns:
      vc
    • getK

      public double[] getK()
      Returns the camera's lens distortion coefficients.
      Returns:
      the vector of lens distortion coefficients
    • getA

      public RealMatrix getA()
      Returns a copy of the camera's inner transformation matrix with contents
          alpha  gamma  uc
              0   beta  vc
       
      Returns:
      the camara's inner transformation matrix (2 x 3)
    • getInverseA

      Returns the inverse of the camera intrinsic matrix A as a 3x3 matrix (without the last row {0,0,1}). This version uses closed form matrix inversion. Used for rectifying images (i.e., removing lens distortion).
      Returns:
      the inverse of the camera intrinsic matrix A
    • getHomography

      Returns the homography for the given view as a 3 x 3 matrix.
      Parameters:
      view - the extrinsic view parameters
      Returns:
      the homography matrix
    • toString

      public String toString()
      Overrides:
      toString in class Object