17 # include <vcl_msvc_warnings.h> 30 world_points_(world_points),
31 image_points_(std::move(image_points))
63 world_points_(world_points),
64 image_points_(std::move(image_points))
78 assert(x.
size() == 6);
79 vnl_double_3 w(x[0], x[1], x[2]);
97 assert(x.
size() == 6);
98 vnl_double_3 w(x[0], x[1], x[2]);
103 std::cout <<
"camera =\n" << cam.get_matrix() << std::endl;
115 world_points_(world_points),
116 image_points_(std::move(image_points))
130 assert(x.
size() == 10);
131 vnl_double_3 w(x[0], x[1], x[2]);
136 kk[0][0]=x[6]; kk[0][2]=x[7];
137 kk[1][1]=x[8]; kk[1][2]=x[9]; kk[2][2]=1.0;
140 if ( !(kk[0][0]>0) || !(kk[1][1]>0) ) {
143 fx[2*i+1] = 100000000;
165 world_points_(world_points),
166 image_points_(std::move(image_points))
179 assert(x.
size() == 8);
188 fx[2*i+1] = 100000000;
210 double norm = sqrt(xvec[0]*xvec[0] + xvec[1]*xvec[1] + xvec[2]*xvec[2] + xvec[3]*xvec[3]);
217 x = q.
x(); y = q.
y(); z = q.
z(); r = q.
r();
229 t1 = t.
x(); t2 = t.
y(); t3 = t.
z();
239 A = Rmat[0][0]*X + Rmat[0][1]*Y + Rmat[0][2]*Z + t1*W;
240 B = Rmat[1][0]*X + Rmat[1][1]*Y + Rmat[1][2]*Z + t2*W;
241 C = Rmat[2][0]*X + Rmat[2][1]*Y + Rmat[2][2]*Z + t3*W;
243 double dex_dr1, dex_dr2, dex_dr3, dex_dr4, dey_dr1, dey_dr2, dey_dr3, dey_dr4;
244 double dex_dt1, dey_dt1, dex_dt2, dey_dt2, dex_dt3, dey_dt3, dex_df, dey_df;
246 dex_dr1 = 2*((W*t1*x + X*x + Y*y + Z*z)*C - (W*t3*x + X*z + Y*r - Z*x)*A)/(C*C);
247 dex_dr2 = 2*((W*t1*y - X*y + Y*x + Z*r)*C - (W*t3*y - X*r + Y*z - Z*y)*A)/(C*C);
248 dex_dr3 = 2*((W*t1*z - X*z - Y*r + Z*x)*C - (W*t3*z + X*x + Y*y + Z*z)*A)/(C*C);
249 dex_dr4 = 2*((W*t1*r + X*r - Y*z + Z*y)*C - (W*t3*r - X*y + Y*x + Z*r)*A)/(C*C);
251 dey_dr1 = 2*((W*t2*x + X*y - Y*x - Z*r)*C - (W*t3*x + X*z + Y*r - Z*x)*B)/(C*C);
252 dey_dr2 = 2*((W*t2*y + X*x + Y*y + Z*z)*C - (W*t3*y - X*r + Y*z - Z*y)*B)/(C*C);
253 dey_dr3 = 2*((W*t2*z + X*r - Y*z + Z*y)*C - (W*t3*z + X*x + Y*y + Z*z)*B)/(C*C);
254 dey_dr4 = 2*((W*t2*r + X*z + Y*r - Z*x)*C - (W*t3*r - X*y + Y*x + Z*r)*B)/(C*C);
256 dex_dr1 *= -F/norm; dex_dr2 *= -F/norm; dex_dr3 *= -F/norm; dex_dr4 *= -F/norm;
257 dey_dr1 *= -F/norm; dey_dr2 *= -F/norm; dey_dr3 *= -F/norm; dey_dr4 *= -F/norm;
259 dey_dt2 = dex_dt1 = -F/C;
260 dex_dt2 = dey_dt1 = 0;
261 dex_dt3 = F*A / (C*C);
262 dey_dt3 = F*B / (C*C);
266 jacobian(2*idx,0) = dex_dr1;
267 jacobian(2*idx,1) = dex_dr2;
268 jacobian(2*idx,2) = dex_dr3;
269 jacobian(2*idx,3) = dex_dr4;
271 jacobian(2*idx,4) = dex_dt1;
272 jacobian(2*idx,5) = dex_dt2;
273 jacobian(2*idx,6) = dex_dt3;
274 jacobian(2*idx,7) = dex_df;
276 jacobian(2*idx+1,0) = dey_dr1;
277 jacobian(2*idx+1,1) = dey_dr2;
278 jacobian(2*idx+1,2) = dey_dr3;
279 jacobian(2*idx+1,3) = dey_dr4;
281 jacobian(2*idx+1,4) = dey_dt1;
282 jacobian(2*idx+1,5) = dey_dt2;
283 jacobian(2*idx+1,6) = dey_dt3;
284 jacobian(2*idx+1,7) = dey_df;
331 params[0]=w[0]; params[1]=w[1]; params[2]=w[2];
332 params[3]=c.
x(); params[4]=c.
y(); params[5]=c.
z();
335 vnl_double_3 w_min(params[0],params[1],params[2]);
346 const double xtol,
const unsigned nevals)
357 params[0] = q.
x(); params[1] = q.
y(); params[2] = q.
z(); params[3] = q.
r();
358 params[4]=t.
x(); params[5]=t.
y(); params[6]=t.
z();
369 double f_min = params[7];
380 const double xtol,
const unsigned nevals)
391 params[0]=w[0]; params[1]=w[1]; params[2]=w[2];
392 params[3]=c.
x(); params[4]=c.
y(); params[5]=c.
z();
393 params[6]=kk[0][0]; params[7]=kk[0][2];
394 params[8]=kk[1][1]; params[9]=kk[1][2];
399 vnl_double_3 w_min(params[0],params[1],params[2]);
402 kk_min.
fill(0); kk_min[2][2]=1.0;
403 kk_min[0][0]=params[6]; kk_min[0][2]=params[7];
404 kk_min[1][1]=params[8]; kk_min[1][2]=params[9];
void set_f_tolerance(double v)
vnl_matrix_fixed< T, 3, 3 > as_matrix() const
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.
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.
vnl_vector_fixed< T, 3 > as_rodrigues() const
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.
vnl_quaternion< T > as_quaternion() const
std::vector< vgl_homg_point_3d< double > > world_points_
The known points in the world.
const vpgl_calibration_matrix< T > & get_calibration() const
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.
const vgl_rotation_3d< T > & get_rotation() const
vpgl_calibration_matrix< double > K_
The fixed internal camera calibration.
virtual void trace(int iteration, vnl_vector< double > const &x, vnl_vector< double > const &fx)
Methods for projecting geometric structures onto the image.
std::vector< vgl_homg_point_3d< double > > world_points_
The known points in the world.
vnl_matrix_fixed< T, 3, 3 > get_matrix() const
Get the calibration matrix.
void set_max_function_evals(int v)
const vgl_point_3d< T > & get_camera_center() const
vnl_matrix_fixed & fill(T)
bool vnl_rotation_matrix(double const x[3], double **R)
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.
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.
void set_focal_length(T new_focal_length)
Getters and setters for all of the parameters.
bool minimize(vnl_vector< double > &x)
vgl_vector_3d< T > get_translation() const
this class optimizes the rotation/translation/calibration of a perspective camera given an initial es...
void set_x_tolerance(double v)
vpgl_orientation_position_calibration_lsqr(const std::vector< vgl_homg_point_3d< double > > &world_points, std::vector< vgl_point_2d< double > > image_points)
Constructor.