Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
vpgl_perspective_camera< T > Class Template Reference

This class implements the perspective camera class as described in Hartley & Zisserman as a finite camera. More...

#include <vpgl_perspective_camera.h>

Inheritance diagram for vpgl_perspective_camera< T >:
Inheritance graph
[legend]

Public Member Functions

 vpgl_perspective_camera ()
 Default constructor. More...
 
 vpgl_perspective_camera (const vpgl_calibration_matrix< T > &K, const vgl_point_3d< T > &camera_center, vgl_rotation_3d< T > R)
 Main constructor takes all of the camera parameters. More...
 
 vpgl_perspective_camera (const vpgl_calibration_matrix< T > &K, vgl_rotation_3d< T > R, const vgl_vector_3d< T > &t)
 Main constructor based on K[R|t]. More...
 
 vpgl_perspective_camera (const vpgl_perspective_camera &cam)
 Copy constructor. More...
 
 ~vpgl_perspective_camera () override=default
 Destructor. More...
 
std::string type_name () const override
 class identity functions for casting. More...
 
vpgl_proj_camera< T > * clone (void) const override
 Clone ‘this’: creation of a new object and initialization. More...
 
vgl_homg_line_3d_2_points< T > backproject (const vgl_homg_point_2d< T > &image_point) const override
 Finite backprojection. More...
 
vgl_line_3d_2_points< T > backproject (const vgl_point_2d< T > &image_point) const
 Finite backprojection. More...
 
vgl_line_3d_2_points< T > backproject (T u, T v) const
 Finite backprojection. More...
 
vgl_ray_3d< T > backproject_ray (const vgl_point_2d< T > &image_point) const
 Finite ray backprojection. More...
 
vgl_ray_3d< T > backproject_ray (T u, T v) const
 Finite ray backprojection at u v. More...
 
vgl_vector_3d< T > principal_axis () const
 Compute the principal axis. More...
 
bool is_behind_camera (const vgl_homg_point_3d< T > &world_point) const
 Determine whether the given point lies in front of the principal plane. More...
 
void set_calibration (const vpgl_calibration_matrix< T > &K)
 Setters and getters. More...
 
void set_camera_center (const vgl_point_3d< T > &camera_center)
 
void set_translation (const vgl_vector_3d< T > &t)
 
void set_rotation (const vgl_rotation_3d< T > &R)
 
const vpgl_calibration_matrix< T > & get_calibration () const
 
const vgl_point_3d< T > & get_camera_center () const
 
vgl_vector_3d< T > get_translation () const
 
const vgl_rotation_3d< T > & get_rotation () const
 
void look_at (const vgl_homg_point_3d< T > &point, const vgl_vector_3d< T > &up=vgl_vector_3d< T >(0, 0, 1))
 Rotate the camera about its center such that it looks at the given point. More...
 
vgl_homg_point_3d< T > camera_center () const override
 Return the known camera center instead of computing it in the base class. More...
 
bool operator== (vpgl_perspective_camera< T > const &that) const
 Equality test. More...
 
void save (std::string cam_path) override
 Save in ascii format. More...
 
virtual vpgl_perspective_camera< T > * cast_to_perspective_camera ()
 Return ‘this’ if ‘this’ is a vpgl_perspective_camera, 0 otherwise. More...
 
virtual const vpgl_perspective_camera< T > * cast_to_perspective_camera () const
 
bool operator== (vpgl_proj_camera< T > const &that) const
 Equality test. More...
 
void project (const T x, const T y, const T z, T &u, T &v) const override
 Projection from base class. More...
 
virtual vgl_homg_point_2d< T > project (const vgl_homg_point_3d< T > &world_point) const
 Project a point in world coordinates onto the image plane. More...
 
vgl_homg_point_2d< T > project (const vgl_point_3d< T > &world_point) const
 Non-homogeneous version of the above. More...
 
vgl_line_segment_2d< T > project (const vgl_line_segment_3d< T > &world_line) const
 Project a line in the world onto a line in the image plane. More...
 
vgl_line_2d< T > project (const vgl_infinite_line_3d< T > &world_line) const
 Project an infinite line in the world onto an infinite line in the image plane. More...
 
vgl_homg_point_2d< T > operator() (const vgl_homg_point_3d< T > &world_point) const
 A shortcut to the above function. More...
 
vgl_line_segment_2d< T > operator() (const vgl_line_segment_3d< T > &world_line) const
 Standard () forward projection operator. More...
 
vgl_line_2d< T > operator() (const vgl_infinite_line_3d< T > &world_line) const
 Standard () forward projection operator. More...
 
virtual vgl_ray_3d< T > backproject_ray (const vgl_homg_point_2d< T > &image_point) const
 Find the 3d ray that goes through the camera center and the provided image point. More...
 
vgl_homg_plane_3d< T > backproject (const vgl_homg_line_2d< T > &image_line) const
 Find the 3d plane that contains the camera center and the provided line in the image plane. More...
 
virtual vgl_homg_plane_3d< T > principal_plane () const
 Find the world plane parallel to the image plane intersecting the camera center. More...
 
vgl_homg_point_2d< T > x_vanishing_point () const
 Find the image coordinates of the vanishing points of the world coordinate axes. More...
 
vgl_homg_point_2d< T > y_vanishing_point () const
 
vgl_homg_point_2d< T > z_vanishing_point () const
 
const vnl_matrix_fixed< T, 3, 4 > & get_matrix () const
 Return a copy of the camera matrix. More...
 
vnl_svd< T > * svd () const
 Get a copy of the svd of the get_matrix. More...
 
virtual bool set_matrix (const vnl_matrix_fixed< T, 3, 4 > &new_camera_matrix)
 Setters mirror the constructors and return true if the setting was successful. More...
 
virtual bool set_matrix (const T *new_camera_matrix)
 
std::string is_a () const
 
bool is_class (std::string const &name) const
 
void ref ()
 
void unref ()
 
long get_references () const
 
bool is_referenced () const
 

Static Public Member Functions

static vpgl_perspective_camera< T > postmultiply (const vpgl_perspective_camera< T > &in_cam, const vgl_h_matrix_3d< T > &euclid_trans)
 Post-multiply this perspective camera with a 3-d Euclidean transformation. More...
 
static vpgl_perspective_camera< T > postmultiply (const vpgl_perspective_camera< T > &camera, const vgl_rotation_3d< T > &rot, const vgl_vector_3d< T > &trans)
 Apply a 3-d Euclidean transformation (transform external cam parameters). More...
 

Protected Member Functions

void recompute_matrix ()
 Recalculate the 3x4 camera matrix from the parameters. More...
 

Protected Attributes

vpgl_calibration_matrix< T > K_
 
vgl_point_3d< T > camera_center_
 
vgl_rotation_3d< T > R_
 

Detailed Description

template<class T>
class vpgl_perspective_camera< T >

This class implements the perspective camera class as described in Hartley & Zisserman as a finite camera.

This is the camera model based on three objects: the camera calibration matrix (see "vpgl_calibration_matrix.h"), the camera center, and the rotation of the camera from its canonical orientation staring down the positive z axis.

All rotation matrices entered will be checked that they are indeed rotations, i.e. that R.transpose()*R = Identity and in the form:

  [ R 0 ]
  [ 0 1 ]
 Modifications
  Feb 12, 2007  Thomas Pollard   Added finite backprojection method.

For adding to this class:

Be sure to call recompute_matrix in your member functions any time you change any of the camera parameters.

Definition at line 59 of file vpgl_perspective_camera.h.

Constructor & Destructor Documentation

◆ vpgl_perspective_camera() [1/4]

template<class T >
vpgl_perspective_camera< T >::vpgl_perspective_camera ( )

Default constructor.

Makes a camera at the origin with no rotation and default calibration matrix.

Definition at line 38 of file vpgl_perspective_camera.hxx.

◆ vpgl_perspective_camera() [2/4]

template<class T >
vpgl_perspective_camera< T >::vpgl_perspective_camera ( const vpgl_calibration_matrix< T > &  K,
const vgl_point_3d< T > &  camera_center,
vgl_rotation_3d< T >  R 
)

Main constructor takes all of the camera parameters.

Definition at line 48 of file vpgl_perspective_camera.hxx.

◆ vpgl_perspective_camera() [3/4]

template<class T >
vpgl_perspective_camera< T >::vpgl_perspective_camera ( const vpgl_calibration_matrix< T > &  K,
vgl_rotation_3d< T >  R,
const vgl_vector_3d< T > &  t 
)

Main constructor based on K[R|t].

Definition at line 59 of file vpgl_perspective_camera.hxx.

◆ vpgl_perspective_camera() [4/4]

template<class T >
vpgl_perspective_camera< T >::vpgl_perspective_camera ( const vpgl_perspective_camera< T > &  cam)

Copy constructor.

Definition at line 71 of file vpgl_perspective_camera.hxx.

◆ ~vpgl_perspective_camera()

template<class T>
vpgl_perspective_camera< T >::~vpgl_perspective_camera ( )
overridedefault

Destructor.

Member Function Documentation

◆ backproject() [1/4]

template<class T >
vgl_homg_line_3d_2_points< T > vpgl_perspective_camera< T >::backproject ( const vgl_homg_point_2d< T > &  image_point) const
overridevirtual

Finite backprojection.

This is a virtual function from the parent class vpgl_proj_camera<T>

Reimplemented from vpgl_proj_camera< T >.

Definition at line 88 of file vpgl_perspective_camera.hxx.

◆ backproject() [2/4]

template<class T >
vgl_line_3d_2_points< T > vpgl_perspective_camera< T >::backproject ( const vgl_point_2d< T > &  image_point) const

Finite backprojection.

Definition at line 101 of file vpgl_perspective_camera.hxx.

◆ backproject() [3/4]

template<class T>
vgl_line_3d_2_points<T> vpgl_perspective_camera< T >::backproject ( u,
v 
) const
inline

Finite backprojection.

Definition at line 95 of file vpgl_perspective_camera.h.

◆ backproject() [4/4]

template<class T >
vgl_homg_plane_3d< T > vpgl_proj_camera< T >::backproject ( const vgl_homg_line_2d< T > &  image_line) const
inherited

Find the 3d plane that contains the camera center and the provided line in the image plane.

Definition at line 178 of file vpgl_proj_camera.hxx.

◆ backproject_ray() [1/3]

template<class T >
vgl_ray_3d< T > vpgl_perspective_camera< T >::backproject_ray ( const vgl_point_2d< T > &  image_point) const

Finite ray backprojection.

Definition at line 123 of file vpgl_perspective_camera.hxx.

◆ backproject_ray() [2/3]

template<class T>
vgl_ray_3d<T> vpgl_perspective_camera< T >::backproject_ray ( u,
v 
) const
inline

Finite ray backprojection at u v.

Definition at line 109 of file vpgl_perspective_camera.h.

◆ backproject_ray() [3/3]

template<class T >
vgl_ray_3d< T > vpgl_proj_camera< T >::backproject_ray ( const vgl_homg_point_2d< T > &  image_point) const
virtualinherited

Find the 3d ray that goes through the camera center and the provided image point.

Reimplemented in vpgl_affine_camera< T >.

Definition at line 162 of file vpgl_proj_camera.hxx.

◆ camera_center()

template<class T>
vgl_homg_point_3d<T> vpgl_perspective_camera< T >::camera_center ( ) const
inlineoverridevirtual

Return the known camera center instead of computing it in the base class.

Reimplemented from vpgl_proj_camera< T >.

Definition at line 138 of file vpgl_perspective_camera.h.

◆ cast_to_perspective_camera() [1/2]

template<class T>
virtual vpgl_perspective_camera<T>* vpgl_perspective_camera< T >::cast_to_perspective_camera ( )
inlinevirtual

Return ‘this’ if ‘this’ is a vpgl_perspective_camera, 0 otherwise.

This is used by e.g. the storage class

Todo:
code for affine camera and other children

Definition at line 169 of file vpgl_perspective_camera.h.

◆ cast_to_perspective_camera() [2/2]

template<class T>
virtual const vpgl_perspective_camera<T>* vpgl_perspective_camera< T >::cast_to_perspective_camera ( ) const
inlinevirtual

Definition at line 170 of file vpgl_perspective_camera.h.

◆ clone()

template<class T >
vpgl_proj_camera< T > * vpgl_perspective_camera< T >::clone ( void  ) const
overridevirtual

Clone ‘this’: creation of a new object and initialization.

See Prototype pattern

Reimplemented from vpgl_proj_camera< T >.

Definition at line 81 of file vpgl_perspective_camera.hxx.

◆ get_calibration()

template<class T>
const vpgl_calibration_matrix<T>& vpgl_perspective_camera< T >::get_calibration ( ) const
inline

Definition at line 124 of file vpgl_perspective_camera.h.

◆ get_camera_center()

template<class T>
const vgl_point_3d<T>& vpgl_perspective_camera< T >::get_camera_center ( ) const
inline

Definition at line 125 of file vpgl_perspective_camera.h.

◆ get_matrix()

template<class T>
const vnl_matrix_fixed<T,3,4>& vpgl_proj_camera< T >::get_matrix ( ) const
inlineinherited

Return a copy of the camera matrix.

Definition at line 156 of file vpgl_proj_camera.h.

◆ get_rotation()

template<class T>
const vgl_rotation_3d<T>& vpgl_perspective_camera< T >::get_rotation ( ) const
inline

Definition at line 127 of file vpgl_perspective_camera.h.

◆ get_translation()

template<class T >
vgl_vector_3d< T > vpgl_perspective_camera< T >::get_translation ( ) const

Definition at line 189 of file vpgl_perspective_camera.hxx.

◆ is_a()

template<class T>
std::string vpgl_camera< T >::is_a ( ) const
inlineinherited

Definition at line 40 of file vpgl_camera.h.

◆ is_behind_camera()

template<class T >
bool vpgl_perspective_camera< T >::is_behind_camera ( const vgl_homg_point_3d< T > &  world_point) const

Determine whether the given point lies in front of the principal plane.

Definition at line 142 of file vpgl_perspective_camera.hxx.

◆ is_class()

template<class T>
bool vpgl_camera< T >::is_class ( std::string const &  name) const
inlineinherited

Definition at line 41 of file vpgl_camera.h.

◆ look_at()

template<class T >
void vpgl_perspective_camera< T >::look_at ( const vgl_homg_point_3d< T > &  point,
const vgl_vector_3d< T > &  up = vgl_vector_3d<T>(0,0,1) 
)

Rotate the camera about its center such that it looks at the given point.

The camera should also be rotated about its principal axis such that the vertical image direction is closest to up in the world

Definition at line 200 of file vpgl_perspective_camera.hxx.

◆ operator()() [1/3]

template<class T>
vgl_homg_point_2d<T> vpgl_proj_camera< T >::operator() ( const vgl_homg_point_3d< T > &  world_point) const
inlineinherited

A shortcut to the above function.

Definition at line 114 of file vpgl_proj_camera.h.

◆ operator()() [2/3]

template<class T>
vgl_line_segment_2d<T> vpgl_proj_camera< T >::operator() ( const vgl_line_segment_3d< T > &  world_line) const
inlineinherited

Standard () forward projection operator.

Definition at line 121 of file vpgl_proj_camera.h.

◆ operator()() [3/3]

template<class T>
vgl_line_2d<T> vpgl_proj_camera< T >::operator() ( const vgl_infinite_line_3d< T > &  world_line) const
inlineinherited

Standard () forward projection operator.

Definition at line 128 of file vpgl_proj_camera.h.

◆ operator==() [1/2]

template<class T>
bool vpgl_proj_camera< T >::operator== ( vpgl_proj_camera< T > const &  that) const
inlineinherited

Equality test.

Definition at line 98 of file vpgl_proj_camera.h.

◆ operator==() [2/2]

template<class T>
bool vpgl_perspective_camera< T >::operator== ( vpgl_perspective_camera< T > const &  that) const
inline

Equality test.

Definition at line 155 of file vpgl_perspective_camera.h.

◆ postmultiply() [1/2]

template<class T >
vpgl_perspective_camera< T > vpgl_perspective_camera< T >::postmultiply ( const vpgl_perspective_camera< T > &  in_cam,
const vgl_h_matrix_3d< T > &  euclid_trans 
)
static

Post-multiply this perspective camera with a 3-d Euclidean transformation.

Todo:
decide whether this needs to be either a static method or a stand-alone function. (Now both are present.)

Definition at line 385 of file vpgl_perspective_camera.hxx.

◆ postmultiply() [2/2]

template<class T >
vpgl_perspective_camera< T > vpgl_perspective_camera< T >::postmultiply ( const vpgl_perspective_camera< T > &  camera,
const vgl_rotation_3d< T > &  rot,
const vgl_vector_3d< T > &  trans 
)
static

Apply a 3-d Euclidean transformation (transform external cam parameters).

Definition at line 412 of file vpgl_perspective_camera.hxx.

◆ principal_axis()

template<class T >
vgl_vector_3d< T > vpgl_perspective_camera< T >::principal_axis ( ) const

Compute the principal axis.

i.e. the vector perpendicular to the image plane pointing towards the front of the camera.

Definition at line 131 of file vpgl_perspective_camera.hxx.

◆ principal_plane()

template<class T>
virtual vgl_homg_plane_3d<T> vpgl_proj_camera< T >::principal_plane ( ) const
inlinevirtualinherited

Find the world plane parallel to the image plane intersecting the camera center.

Reimplemented in vpgl_affine_camera< T >.

Definition at line 146 of file vpgl_proj_camera.h.

◆ project() [1/5]

template<class T >
void vpgl_proj_camera< T >::project ( const T  x,
const T  y,
const T  z,
T &  u,
T &  v 
) const
overridevirtualinherited

Projection from base class.

Implements vpgl_camera< T >.

Definition at line 104 of file vpgl_proj_camera.hxx.

◆ project() [2/5]

template<class T >
vgl_homg_point_2d< T > vpgl_proj_camera< T >::project ( const vgl_homg_point_3d< T > &  world_point) const
virtualinherited

Project a point in world coordinates onto the image plane.

Definition at line 85 of file vpgl_proj_camera.hxx.

◆ project() [3/5]

template<class T>
vgl_homg_point_2d<T> vpgl_proj_camera< T >::project ( const vgl_point_3d< T > &  world_point) const
inlineinherited

Non-homogeneous version of the above.

Definition at line 110 of file vpgl_proj_camera.h.

◆ project() [4/5]

template<class T >
vgl_line_segment_2d< T > vpgl_proj_camera< T >::project ( const vgl_line_segment_3d< T > &  world_line) const
inherited

Project a line in the world onto a line in the image plane.

Definition at line 121 of file vpgl_proj_camera.hxx.

◆ project() [5/5]

template<class T >
vgl_line_2d< T > vpgl_proj_camera< T >::project ( const vgl_infinite_line_3d< T > &  world_line) const
inherited

Project an infinite line in the world onto an infinite line in the image plane.

Definition at line 134 of file vpgl_proj_camera.hxx.

◆ recompute_matrix()

template<class T >
void vpgl_perspective_camera< T >::recompute_matrix ( )
protected

Recalculate the 3x4 camera matrix from the parameters.

Definition at line 252 of file vpgl_perspective_camera.hxx.

◆ save()

template<class Type >
void vpgl_perspective_camera< Type >::save ( std::string  cam_path)
overridevirtual

Save in ascii format.

Reimplemented from vpgl_proj_camera< T >.

Definition at line 460 of file vpgl_perspective_camera.hxx.

◆ set_calibration()

template<class T >
void vpgl_perspective_camera< T >::set_calibration ( const vpgl_calibration_matrix< T > &  K)

Setters and getters.

Definition at line 154 of file vpgl_perspective_camera.hxx.

◆ set_camera_center()

template<class T >
void vpgl_perspective_camera< T >::set_camera_center ( const vgl_point_3d< T > &  camera_center)

Definition at line 162 of file vpgl_perspective_camera.hxx.

◆ set_matrix() [1/2]

template<class T >
bool vpgl_proj_camera< T >::set_matrix ( const vnl_matrix_fixed< T, 3, 4 > &  new_camera_matrix)
virtualinherited

Setters mirror the constructors and return true if the setting was successful.

In subclasses these should be redefined so that they won't allow setting of matrices with improper form.

Reimplemented in vpgl_affine_camera< T >.

Definition at line 220 of file vpgl_proj_camera.hxx.

◆ set_matrix() [2/2]

template<class T >
bool vpgl_proj_camera< T >::set_matrix ( const T *  new_camera_matrix)
virtualinherited

Reimplemented in vpgl_affine_camera< T >.

Definition at line 230 of file vpgl_proj_camera.hxx.

◆ set_rotation()

template<class T >
void vpgl_perspective_camera< T >::set_rotation ( const vgl_rotation_3d< T > &  R)

Definition at line 181 of file vpgl_perspective_camera.hxx.

◆ set_translation()

template<class T >
void vpgl_perspective_camera< T >::set_translation ( const vgl_vector_3d< T > &  t)

Definition at line 171 of file vpgl_perspective_camera.hxx.

◆ svd()

template<class T >
vnl_svd< T > * vpgl_proj_camera< T >::svd ( ) const
inherited

Get a copy of the svd of the get_matrix.

The svd is cached when first computed and automatically recomputed when the matrix is changed.

Definition at line 203 of file vpgl_proj_camera.hxx.

◆ type_name()

template<class T>
std::string vpgl_perspective_camera< T >::type_name ( ) const
inlineoverridevirtual

class identity functions for casting.

Reimplemented from vpgl_camera< T >.

Definition at line 83 of file vpgl_perspective_camera.h.

◆ x_vanishing_point()

template<class T>
vgl_homg_point_2d<T> vpgl_proj_camera< T >::x_vanishing_point ( ) const
inlineinherited

Find the image coordinates of the vanishing points of the world coordinate axes.

Definition at line 149 of file vpgl_proj_camera.h.

◆ y_vanishing_point()

template<class T>
vgl_homg_point_2d<T> vpgl_proj_camera< T >::y_vanishing_point ( ) const
inlineinherited

Definition at line 150 of file vpgl_proj_camera.h.

◆ z_vanishing_point()

template<class T>
vgl_homg_point_2d<T> vpgl_proj_camera< T >::z_vanishing_point ( ) const
inlineinherited

Definition at line 151 of file vpgl_proj_camera.h.

Member Data Documentation

◆ camera_center_

template<class T>
vgl_point_3d<T> vpgl_perspective_camera< T >::camera_center_
protected

Definition at line 177 of file vpgl_perspective_camera.h.

◆ K_

template<class T>
vpgl_calibration_matrix<T> vpgl_perspective_camera< T >::K_
protected

Definition at line 176 of file vpgl_perspective_camera.h.

◆ R_

template<class T>
vgl_rotation_3d<T> vpgl_perspective_camera< T >::R_
protected

Definition at line 178 of file vpgl_perspective_camera.h.


The documentation for this class was generated from the following files: