vpgl_optimize_camera.h
Go to the documentation of this file.
1 // This is core/vpgl/algo/vpgl_optimize_camera.h
2 #ifndef vpgl_optimize_camera_h_
3 #define vpgl_optimize_camera_h_
4 //:
5 // \file
6 // \brief Methods for projecting geometric structures onto the image
7 // \author Matt Leotta
8 // \date March 7, 2005
9 //
11 #include <vgl/vgl_point_2d.h>
12 #include <vgl/vgl_point_3d.h>
13 #include <vgl/vgl_homg_point_3d.h>
15 
16 //: this class optimizes the rotation of a perspective camera given an initial estimate and a known internal calibration and position
18 {
19  public:
20  //: Constructor
21  // \note image points are not homogeneous because require finite points to measure projection error
23  const vgl_point_3d<double>& c,
24  const std::vector<vgl_homg_point_3d<double> >& world_points,
25  std::vector<vgl_point_2d<double> > image_points );
26  //: Destructor
27  ~vpgl_orientation_lsqr() override = default;
28 
29  //: The main function.
30  // Given the parameter vector x, compute the vector of residuals fx.
31  // Fx has been sized appropriately before the call.
32  // The parameters in x are the {wx, wy, wz}
33  // where w is the Rodrigues vector of the rotation.
34  void f(vnl_vector<double> const& x, vnl_vector<double>& fx) override;
35 
36 #if 0
37  //: Called after each LM iteration to print debugging etc.
38  virtual void trace(int iteration, vnl_vector<double> const& x, vnl_vector<double> const& fx);
39 #endif
40 
41  protected:
42  //: The fixed internal camera calibration
44  //: The fixed camera center
46  //: The known points in the world
47  std::vector<vgl_homg_point_3d<double> > world_points_;
48  //: The corresponding points in the image
49  std::vector<vgl_point_2d<double> > image_points_;
50 };
51 
52 
53 //: this class optimizes the rotation/translation of a perspective camera given an initial estimate and a known internal calibration
55 {
56  public:
57  //: Constructor
58  // \note image points are not homogeneous because require finite points to measure projection error
60  const std::vector<vgl_homg_point_3d<double> >& world_points,
61  std::vector<vgl_point_2d<double> > image_points );
62  //: Destructor
63  ~vpgl_orientation_position_lsqr() override = default;
64 
65  //: The main function.
66  // Given the parameter vector x, compute the vector of residuals fx.
67  // Fx has been sized appropriately before the call.
68  // The parameters in x are really two three component vectors {wx, wy, wz, tx, ty, tz}
69  // where w is the Rodrigues vector of the rotation and t is the translation.
70  void f(vnl_vector<double> const& x, vnl_vector<double>& fx) override;
71 
72 #if 0
73  //: Called after each LM iteration to print debugging etc.
74  virtual void trace(int iteration, vnl_vector<double> const& x, vnl_vector<double> const& fx);
75 #endif
76 
77  protected:
78  //: The fixed internal camera calibration
80  //: The known points in the world
81  std::vector<vgl_homg_point_3d<double> > world_points_;
82  //: The corresponding points in the image
83  std::vector<vgl_point_2d<double> > image_points_;
84 };
85 
86 //: this class optimizes the rotation/translation/calibration of a perspective camera given an initial estimate
88 {
89  public:
90  //: Constructor
91  // \note image points are not homogeneous because require finite points to measure projection error
93  std::vector<vgl_point_2d<double> > image_points );
94  //: Destructor
96 
97  //: The main function.
98  // Given the parameter vector x, compute the vector of residuals fx.
99  // Fx has been sized appropriately before the call.
100  // The parameters in x are really two three component vectors {wx, wy, wz, tx, ty, tz}
101  // where w is the Rodrigues vector of the rotation and t is the translation.
102  void f(vnl_vector<double> const& x, vnl_vector<double>& fx) override;
103 
104 #if 0
105  //: Called after each LM iteration to print debugging etc.
106  virtual void trace(int iteration, vnl_vector<double> const& x, vnl_vector<double> const& fx);
107 #endif
108 
109  protected:
110  //: The known points in the world
111  std::vector<vgl_homg_point_3d<double> > world_points_;
112  //: The corresponding points in the image
113  std::vector<vgl_point_2d<double> > image_points_;
114 };
115 
116 //: this class optimizes the rotation/translation/focal length of a perspective camera given an initial estimate
118 {
119  public:
120  //: Constructor
121  // \note image points are not homogeneous because require finite points to measure projection error
123  const std::vector<vgl_homg_point_3d<double> >& world_points,
124  std::vector<vgl_point_2d<double> > image_points );
125  //: Destructor
126  ~vpgl_orientation_position_focal_lsqr() override = default;
127 
128  //: The main function.
129  // Given the parameter vector x, compute the vector of residuals fx.
130  // Fx has been sized appropriately before the call.
131  // The parameters in x are really two three component vectors {wx, wy, wz, tx, ty, tz}
132  // where w is the Rodrigues vector of the rotation and t is the translation.
133  void f(vnl_vector<double> const& x, vnl_vector<double>& fx) override;
134 
135  //: Gradients of the cost-function w.r.t. to the 7 free parameters of x
136  // The seven parameters are rotation(wx, wy, wz), translation(tx, ty, tz) and focal length (Fx)
137  void gradf(vnl_vector<double> const&x, vnl_matrix<double>& jacobian) override;
138 
139 #if 0
140  //: Called after each LM iteration to print debugging etc.
141  virtual void trace(int iteration, vnl_vector<double> const& x, vnl_vector<double> const& fx);
142 #endif
143 
144  protected:
145  //: The initial calibration matrix
147  //: The known points in the world
148  std::vector<vgl_homg_point_3d<double> > world_points_;
149  //: The corresponding points in the image
150  std::vector<vgl_point_2d<double> > image_points_;
151 };
152 
153 
154 
156 {
157  public:
159 
160  //: optimize orientation for a perspective camera
163  const std::vector<vgl_homg_point_3d<double> >& world_points,
164  const std::vector<vgl_point_2d<double> >& image_points );
165 
166  //: optimize orientation and position for a perspective camera
169  const std::vector<vgl_homg_point_3d<double> >& world_points,
170  const std::vector<vgl_point_2d<double> >& image_points );
171 
172  //: optimize orientation, position and focal length for a perspective camera
175  const std::vector<vgl_homg_point_3d<double> >& world_points,
176  const std::vector<vgl_point_2d<double> >& image_points,
177  const double xtol = 0.0001, const unsigned nevals=10000);
178 
179  //: optimize orientation, position and internal calibration(no skew)for a perspective camera
182  const std::vector<vgl_homg_point_3d<double> >& world_points,
183  const std::vector<vgl_point_2d<double> >& image_points,
184  const double xtol = 0.0001, const unsigned nevals=10000);
185 
186 
187  private:
188  //: Constructor private - static methods only
190 };
191 
192 #endif // vpgl_optimize_camera_h_
A class for the perspective camera model.
~vpgl_orientation_position_lsqr() override=default
Destructor.
void f(vnl_vector< double > const &x, vnl_vector< double > &fx) override
The main function.
std::vector< vgl_point_2d< double > > image_points_
The corresponding points in the image.
std::vector< vgl_point_2d< double > > image_points_
The corresponding points in the image.
vpgl_calibration_matrix< double > K_
The fixed internal camera calibration.
void gradf(vnl_vector< double > const &x, vnl_matrix< double > &jacobian) override
Gradients of the cost-function w.r.t. to the 7 free parameters of x.
std::vector< vgl_point_2d< double > > image_points_
The corresponding points in the image.
static vpgl_perspective_camera< double > opt_orient_pos_f(const vpgl_perspective_camera< double > &camera, const std::vector< vgl_homg_point_3d< double > > &world_points, const std::vector< vgl_point_2d< double > > &image_points, const double xtol=0.0001, const unsigned nevals=10000)
optimize orientation, position and focal length for a perspective camera.
vpgl_optimize_camera()
Constructor private - static methods only.
this class optimizes the rotation/translation of a perspective camera given an initial estimate and a...
vpgl_orientation_lsqr(const vpgl_calibration_matrix< double > &K, const vgl_point_3d< double > &c, const std::vector< vgl_homg_point_3d< double > > &world_points, std::vector< vgl_point_2d< double > > image_points)
Constructor.
std::vector< vgl_point_2d< double > > image_points_
The corresponding points in the image.
vgl_point_3d< double > c_
The fixed camera center.
static vpgl_perspective_camera< double > opt_orient(const vpgl_perspective_camera< double > &camera, const std::vector< vgl_homg_point_3d< double > > &world_points, const std::vector< vgl_point_2d< double > > &image_points)
optimize orientation for a perspective camera.
vpgl_calibration_matrix< double > K_init_
The initial calibration matrix.
this class optimizes the rotation of a perspective camera given an initial estimate and a known inter...
std::vector< vgl_homg_point_3d< double > > world_points_
The known points in the world.
std::vector< vgl_homg_point_3d< double > > world_points_
The known points in the world.
static vpgl_perspective_camera< double > opt_orient_pos_cal(const vpgl_perspective_camera< double > &camera, const std::vector< vgl_homg_point_3d< double > > &world_points, const std::vector< vgl_point_2d< double > > &image_points, const double xtol=0.0001, const unsigned nevals=10000)
optimize orientation, position and internal calibration(no skew)for a perspective camera.
vpgl_calibration_matrix< double > K_
The fixed internal camera calibration.
~vpgl_orientation_lsqr() override=default
Destructor.
virtual void trace(int iteration, vnl_vector< double > const &x, vnl_vector< double > const &fx)
std::vector< vgl_homg_point_3d< double > > world_points_
The known points in the world.
void f(vnl_vector< double > const &x, vnl_vector< double > &fx) override
The main function.
static vpgl_perspective_camera< double > opt_orient_pos(const vpgl_perspective_camera< double > &camera, const std::vector< vgl_homg_point_3d< double > > &world_points, const std::vector< vgl_point_2d< double > > &image_points)
optimize orientation and position for a perspective camera.
void f(vnl_vector< double > const &x, vnl_vector< double > &fx) override
The main function.
This class implements the perspective camera class as described in Hartley & Zisserman as a finite ca...
std::vector< vgl_homg_point_3d< double > > world_points_
The known points in the world.
void f(vnl_vector< double > const &x, vnl_vector< double > &fx) override
The main function.
~vpgl_orientation_position_focal_lsqr() override=default
Destructor.
this class optimizes the rotation/translation/focal length of a perspective camera given an initial e...
vpgl_orientation_position_focal_lsqr(const vpgl_calibration_matrix< double > &K_init, const std::vector< vgl_homg_point_3d< double > > &world_points, std::vector< vgl_point_2d< double > > image_points)
Constructor.
vpgl_orientation_position_lsqr(const vpgl_calibration_matrix< double > &K, const std::vector< vgl_homg_point_3d< double > > &world_points, std::vector< vgl_point_2d< double > > image_points)
Constructor.
~vpgl_orientation_position_calibration_lsqr() override=default
Destructor.
this class optimizes the rotation/translation/calibration of a perspective camera given an initial es...
vpgl_orientation_position_calibration_lsqr(const std::vector< vgl_homg_point_3d< double > > &world_points, std::vector< vgl_point_2d< double > > image_points)
Constructor.