vpgl_perspective_camera.hxx
Go to the documentation of this file.
1 // This is core/vpgl/vpgl_perspective_camera.hxx
2 #ifndef vpgl_perspective_camera_hxx_
3 #define vpgl_perspective_camera_hxx_
4 //:
5 // \file
6 
7 #include <algorithm>
8 #include <fstream>
9 #include <iostream>
10 #include <utility>
12 
13 #include <vgl/vgl_point_2d.h>
14 #include <vgl/vgl_vector_3d.h>
15 #include <vgl/vgl_homg_plane_3d.h>
18 #include <vnl/vnl_det.h>
19 #include <vnl/algo/vnl_qr.h>
20 #include <vnl/vnl_matrix_fixed.h>
21 #if 0
22 #include <vgl/io/vgl_io_point_3d.h>
25 #endif
26 #include <vul/vul_file.h>
27 #include <vul/vul_file_iterator.h>
28 
29 #include <cassert>
30 #ifdef _MSC_VER
31 # include <vcl_msvc_warnings.h>
32 #endif
33 
34 #include <vnl/vnl_trace.h>
35 
36 //-------------------------------------------
37 template <class T>
39 {
40  R_.set_identity();
41  camera_center_.set( (T)0, (T)0, (T)0 );
42  recompute_matrix();
43 }
44 
45 
46 //-------------------------------------------
47 template <class T>
50  const vgl_point_3d<T>& camera_center,
51  const vgl_rotation_3d<T> R ) :
52  K_( K ), camera_center_( camera_center ), R_(std::move( R ))
53 {
55 }
56 
57 //-------------------------------------------
58 template <class T>
61  const vgl_rotation_3d<T> R,
62  const vgl_vector_3d<T>& t) :
63  K_( K ), R_(std::move( R ))
64 {
65  this->set_translation(t);
67 }
68 
69 //-------------------------------------------
70 template <class T>
72  : vpgl_proj_camera<T>(that),
73  K_(that.K_),
74  camera_center_(that.camera_center_),
75  R_(that.R_)
76 {
77 }
78 
79 //-------------------------------------------
80 template <class T>
82 {
83  return new vpgl_perspective_camera<T>(*this);
84 }
85 
86 //------------------------------------
87 template <class T>
89  const vgl_homg_point_2d<T>& image_point ) const
90 {
91  // First find a point that projects to "image_point".
92  vnl_vector_fixed<T,4> vnl_wp = this->svd()->solve(
93  vnl_vector_fixed<T,3>( image_point.x(), image_point.y(), image_point.w() ).as_ref() );
94  vgl_homg_point_3d<T> wp( vnl_wp[0], vnl_wp[1], vnl_wp[2], vnl_wp[3] );
95  // The ray is then defined by that point and the camera center.
96  return vgl_homg_line_3d_2_points<T>( vgl_homg_point_3d<T>(camera_center_), wp );
97 }
98 
99 //------------------------------------
100 template <class T>
102  const vgl_point_2d<T>& image_point ) const
103 {
104  // First find a point in front of the camera that projects to "image_point".
105  vnl_vector_fixed<T,4> vnl_wp = this->svd()->solve(
106  vnl_vector_fixed<T,3>( image_point.x(), image_point.y(), 1.0 ).as_ref() );
107  vgl_homg_point_3d<T> wp_homg( vnl_wp[0], vnl_wp[1], vnl_wp[2], vnl_wp[3] );
108  vgl_point_3d<T> wp;
109  if ( !wp_homg.ideal() )
110  wp.set( wp_homg.x()/wp_homg.w(), wp_homg.y()/wp_homg.w(), wp_homg.z()/wp_homg.w() );
111  else
112  wp.set( camera_center_.x()+wp_homg.x(),
113  camera_center_.y()+wp_homg.y(),
114  camera_center_.z()+wp_homg.z() );
115  if ( is_behind_camera( vgl_homg_point_3d<T>( wp ) ) )
116  wp = camera_center_ + ( camera_center_-wp );
117  // The ray is then defined by that point and the camera center.
118  return vgl_line_3d_2_points<T>( camera_center_, wp );
119 }
120 
121 template <class T>
123 backproject_ray( const vgl_point_2d<T>& image_point ) const
124 {
125  vgl_line_3d_2_points<T> l2 = this->backproject(image_point);
126  return vgl_ray_3d<T>(l2.point1(), l2.direction());
127 }
128 
129 //-------------------------------------------
130 template <class T>
132 {
133  // See H&Z pg 147
134  // P = [M|p4] : We do not need to compute det(M) because we enforce
135  // det(K)>0 and det(R)=1 in the construction of P. Thus det(M)>0;
136  const vnl_matrix_fixed<T,3,4>& P = this->get_matrix();
137  return normalized(vgl_vector_3d<T>(P(2,0),P(2,1),P(2,2)));
138 }
139 
140 //------------------------------------
141 template <class T>
143  const vgl_homg_point_3d<T>& world_point ) const
144 {
145  vgl_homg_plane_3d<T> l = this->principal_plane();
146  T dot = world_point.x()*l.a() + world_point.y()*l.b() +
147  world_point.z()*l.c() + world_point.w()*l.d();
148  if (world_point.w() < (T)0) dot = ((T)(-1))*dot;
149  return dot < 0;
150 }
151 
152 //-------------------------------------------
153 template <class T>
155 {
156  K_ = K;
157  recompute_matrix();
158 }
159 
160 //-------------------------------------------
161 template <class T>
163  const vgl_point_3d<T>& camera_center )
164 {
165  camera_center_ = camera_center;
166  recompute_matrix();
167 }
168 
169 //-------------------------------------------
170 template <class T>
172 {
173  vgl_rotation_3d<T> Rt = R_.transpose();
174  vgl_vector_3d<T> cv = -(Rt * t);
175  camera_center_.set(cv.x(), cv.y(), cv.z());
176  recompute_matrix();
177 }
178 
179 //-------------------------------------------
180 template <class T>
182 {
183  R_ = R;
184  recompute_matrix();
185 }
186 
187 //-------------------------------------------
188 template <class T>
190 {
191  vgl_vector_3d<T> c(camera_center_.x(), camera_center_.y(),camera_center_.z());
192  vgl_vector_3d<T> temp = R_*c;
193  return -temp;
194 }
195 
196 //: Rotate the camera about its center such that it looks at the given point
197 // The camera should also be rotated about its principal axis such that
198 // the vertical image direction is closest to \p up in the world
199 template <class T>
201  const vgl_vector_3d<T>& up )
202 {
204  vgl_vector_3d<T> look = point - camera_center();
205  normalize(look);
206 
207 #if 0
208  T dp = dot_product(look, up);
209  bool singularity = std::fabs(std::fabs(static_cast<double>(dp))-1.0)<1e-08;
210  assert(!singularity);
211 #endif
212  vgl_vector_3d<T> z = look;
213 
214  if (std::fabs(dot_product<T>(u,z)-T(1))<1e-5)
215  {
216  T r[] = { 1, 0, 0,
217  0, 1, 0,
218  0, 0, 1 };
219 
221  set_rotation(vgl_rotation_3d<T>(R));
222  }
223  else if (std::fabs(dot_product<T>(u,z)-T(-1))<1e-5)
224  {
225  T r[] = { 1, 0, 0,
226  0, 1, 0,
227  0, 0, -1 };
228 
230  set_rotation(vgl_rotation_3d<T>(R));
231  }
232  else
233  {
236  normalize(x);
237  normalize(y);
238  normalize(z);
239 
240  T r[] = { x.x(), x.y(), x.z(),
241  y.x(), y.y(), y.z(),
242  z.x(), z.y(), z.z() };
243 
245  set_rotation(vgl_rotation_3d<T>(R));
246  }
247 }
248 
249 
250 //-------------------------------------------
251 template <class T>
253 {
254  vnl_matrix_fixed<T,3,4> Pnew( (T)0 );
255 
256  // Set new projection matrix to [ I | -C ].
257  for ( int i = 0; i < 3; i++ )
258  Pnew(i,i) = (T)1;
259  Pnew(0,3) = -camera_center_.x();
260  Pnew(1,3) = -camera_center_.y();
261  Pnew(2,3) = -camera_center_.z();
262 
263  // Then multiply on left to get KR[ I | -C ].
264  this->set_matrix(K_.get_matrix()*R_.as_matrix()*Pnew);
265 }
266 
267 
268 //-------------------------------------------
269 template <class T>
271  vpgl_perspective_camera<T>& p_camera )
272 {
273  // Extract the left sub matrix H from [ H t ] and check that it has rank 3.
274  vnl_matrix_fixed<T,3,3> H = camera_matrix.extract(3,3);
275  vnl_vector_fixed<T,3> t = camera_matrix.get_column(3);
276 
277  T det = vnl_det(H);
278  if ( det == (T)0 ) return false;
279  // To insure a true rotation (determinant = 1) we must start with a positive
280  // determinant H. This is decomposed into K and R, each with positive determinant.
281  if ( det < (T)0 ) {
282  H *= (T)-1;
283  t *= (T)-1;
284  }
285 
286  // Now find the RQ decomposition of the sub matrix and use these to find the params.
287  // This will involve some trickery as VXL has no RQ decomposition, but does have QR.
288  // Define a matrix "flipping" operation by f(A)ij = An-j,n-i i.e. f flips the matrix
289  // about its LL-UR diagonal. One can prove that if f(A) = B*C then A = f(A)*f(B). So
290  // we get the RQ decomposition of A by flipping A, then taking the QR decomposition,
291  // then flipping both back, noting that the flipped Q and R will remain orthogonal and
292  // upper right triangular respectively.
294  for ( int i = 0; i < 3; i++ )
295  for ( int j = 0; j < 3; j++ )
296  Hf(i,j) = H(2-j,2-i);
297  vnl_qr<T> QR( Hf.as_ref() );
298  vnl_matrix_fixed<T,3,3> q,r,Qf,Rf;
299  q = QR.Q();
300  r = QR.R();
301  for ( int i = 0; i < 3; i++ ) {
302  for ( int j = 0; j < 3; j++ ) {
303  Qf(i,j) = q(2-j,2-i);
304  Rf(i,j) = r(2-j,2-i);
305  }
306  }
307 
308  // We almost have the K and R parameter blocks, but we must be sure that the diagonal
309  // entries of K are positive.
310  int r0pos = Rf(0,0) > 0 ? 1 : -1;
311  int r1pos = Rf(1,1) > 0 ? 1 : -1;
312  int r2pos = Rf(2,2) > 0 ? 1 : -1;
313  int diag[3] = { r0pos, r1pos, r2pos };
315  for ( int i = 0; i < 3; i++ ) {
316  for ( int j = 0; j < 3; j++ ) {
317  K1(i,j) = diag[j]*Rf(i,j);
318  R1(i,j) = diag[i]*Qf(i,j);
319  }
320  }
321  K1 = K1/K1(2,2);
322 
323  // Now we extract the parameters from the matrices we've computed;
324  vpgl_calibration_matrix<T> new_K( K1 );
325  p_camera.set_calibration( new_K );
326 
327  vnl_qr<T> QRofH(H.as_ref()); // size 3x3
328  vnl_vector<T> c1 = -QRofH.solve(t.as_ref());
329  vgl_point_3d<T> new_c( c1(0), c1(1), c1(2) );
330  p_camera.set_camera_center( new_c );
331 
332  p_camera.set_rotation( vgl_rotation_3d<T>(R1) );
333 
334  return true;
335 }
336 
337 
338 //-------------------------------------------
339 template <class T>
341  const vpgl_perspective_camera<T>& p0,
342  const vpgl_perspective_camera<T>& p1 )
343 {
344  vpgl_perspective_camera<T> new_camera;
345  new_camera.set_calibration( p0.get_calibration() );
346  new_camera.set_rotation( p1.get_rotation()*p0.get_rotation().inverse() );
349  vgl_point_3d<T> new_camera_center(a1.x() - a0.x(),
350  a1.y() - a0.y(),
351  a1.z() - a0.z() );
352  new_camera.set_camera_center( new_camera_center );
353  return new_camera;
354 }
355 
356 
357 //-------------------------------------------
358 template <class T>
360  const vpgl_perspective_camera<T>& p0,
361  const vpgl_perspective_camera<T>& p1 )
362 {
363  vpgl_perspective_camera<T> new_camera;
364  new_camera.set_calibration( p0.get_calibration() );
365  new_camera.set_rotation( p1.get_rotation()*p0.get_rotation() );
366  vgl_point_3d<T> a = p0.get_rotation().inverse()*p1.get_camera_center();
367  vgl_point_3d<T> new_camera_center( p0.get_camera_center().x() + a.x(),
368  p0.get_camera_center().y() + a.y(),
369  p0.get_camera_center().z() + a.z() );
370  new_camera.set_camera_center( new_camera_center );
371  return new_camera;
372 }
373 
374 
375 //Post-multiply this perspective camera with a 3-d Euclidean transformation
376 // Must check if the transformation is Euclidean, i.e. rotation matrix
377 // and translation. Since we can only work with the external interface
378 // the update due to the postmultiplication is:
379 // K' = K
380 // R' = R*Re
381 // cc' = transpose(Re)(cc - te)
382 // where Re and te are the rotation matrix and
383 // translation vector of the euclidean transform
384 template <class T> vpgl_perspective_camera<T>
386 {
387  assert(euclid_trans.is_euclidean());
388  const vpgl_calibration_matrix<T>& K = in_cam.get_calibration();
389  const vgl_rotation_3d<T>& R = in_cam.get_rotation();
390  const vgl_point_3d<T>& cc = in_cam.get_camera_center();
391  vgl_rotation_3d<T> Re(euclid_trans.get_upper_3x3());
392  vgl_homg_point_3d<T> t = euclid_trans.get_translation();
393 
394  //The transformed rotation matrix
395  vgl_rotation_3d<T> Rp(R*Re);
396 
397  //must have Euclidean quantities to proceed
398  assert(!t.ideal());
399 
400  //Transform the camera center
401  //get the Euclidean components
402  vgl_vector_3d<T> te(t.x()/t.w(), t.y()/t.w(), t.z()/t.w());
403 
404  //construct the transformed center
405  vgl_point_3d<T> ccp = Re.inverse()*(cc-te);
406 
407  return vpgl_perspective_camera<T>(K, ccp, Rp);
408 }
409 
410 template <class T>
413  const vgl_rotation_3d<T>& rot, const vgl_vector_3d<T>& trans)
414 {
416  H.set_identity();
418  H.set_translation(trans.x(), trans.y(), trans.z());
420 }
421 
422 // I/O :------------------------------------------------
423 
424 //: Write vpgl_perspective_camera to stream
425 template <class Type>
426 std::ostream& operator<<(std::ostream& s,
428 {
429  vnl_matrix_fixed<Type, 3, 3> k = p.get_calibration().get_matrix();
433  s << k << '\n'
434  << Rm << '\n'
435  << t.x() << ' ' << t.y() << ' ' << t.z() << '\n';
436  return s ;
437 }
438 
439 //: Read camera from stream
440 template <class Type>
441 std::istream& operator >>(std::istream& s,
443 {
446  s >> k;
447  s >> Rm;
448  s >> tv;
450  vgl_rotation_3d<Type> rot(Rm);
451  vgl_vector_3d<Type> t(tv[0], tv[1], tv[2]);
452  p.set_calibration(K);
453  p.set_rotation(rot);
454  p.set_translation(t);
455  return s ;
456 }
457 
458 //: Save in ascii format
459 template <class Type>
460 void vpgl_perspective_camera<Type>::save(std::string cam_path)
461 {
462  std::ofstream os(cam_path.c_str());
463  if (!os.is_open()) {
464  std::cout << "unable to open output stream in vpgl_proj_camera<T>::save(.)\n";
465  return;
466  }
467  os << *this << '\n';
468  os.close();
469 }
470 
471 //: Write vpgl_perspective_camera to a vrml file
472 template <class Type>
473 void vrml_write(std::ostream& str, vpgl_perspective_camera<Type> const& p, double rad)
474 {
476  str << "Transform {\n"
477  << "translation " << cent.x() << ' ' << cent.y() << ' '
478  << ' ' << cent.z() << '\n'
479  << "children [\n"
480  << "Shape {\n"
481  << " appearance Appearance{\n"
482  << " material Material\n"
483  << " {\n"
484  << " diffuseColor " << 1 << ' ' << 1.0 << ' ' << 0.0 << '\n'
485  << " transparency " << 0.0 << '\n'
486  << " }\n"
487  << " }\n"
488  << " geometry Sphere\n"
489  << "{\n"
490  << " radius " << rad << '\n'
491  << " }\n"
492  << " }\n"
493  << " ]\n"
494  << "}\n";
496  std::cout<<"principal axis :" <<r<<std::endl;
497  vnl_vector_fixed<Type,3> yaxis(0.0, 1.0, 0.0), pvec(r.x(), r.y(), r.z());
498  vgl_rotation_3d<Type> rot(yaxis, pvec);
499  vnl_quaternion<Type> q = rot.as_quaternion();
500 
501  //vnl_double_3 axis = q.axis();
502  vnl_vector_fixed<Type,3> axis = q.axis();
503  std::cout<<"quaternion "<<axis<< " angle "<<q.angle()<<"\n\n";
504  double ang = q.angle();
505  str << "Transform {\n"
506  << " translation " << cent.x()+6*rad*r.x() << ' ' << cent.y()+6*rad*r.y()
507  << ' ' << cent.z()+6*rad*r.z() << '\n'
508  << " rotation " << axis[0] << ' ' << axis[1] << ' ' << axis[2] << ' ' << ang << '\n'
509  << "children [\n"
510  << " Shape {\n"
511  << " appearance Appearance{\n"
512  << " material Material\n"
513  << " {\n"
514  << " diffuseColor 1 0 0\n"
515  << " transparency 0\n"
516  << " }\n"
517  << " }\n"
518  << " geometry Cylinder\n"
519  << "{\n"
520  << " radius "<<rad/3<<'\n'
521  << " height " << 12*rad << '\n'
522  << " }\n"
523  << " }\n"
524  << "]\n"
525  << "}\n";
526 }
527 
528 
529 //: Return a list of camera's, loaded from the (name sorted) files from the given directory
530 template <class T>
531 std::vector<vpgl_perspective_camera<T> > cameras_from_directory(std::string dir, T)
532 {
533  std::vector<vpgl_perspective_camera<T> > camlist;
534  if (!vul_file::is_directory(dir.c_str()) ) {
535  std::cerr << "cameras_from_directory: " << dir << " is not a directory\n";
536  return camlist;
537  }
538 
539  //get all of the cam and image files, sort them
540  std::string camglob=dir+"/*";
541  vul_file_iterator file_it(camglob.c_str());
542  std::vector<std::string> cam_files;
543  while (file_it) {
544  std::string camName(file_it());
545  cam_files.push_back(camName);
546  ++file_it;
547  }
548  std::sort(cam_files.begin(), cam_files.end());
549 
550  //take sorted lists and load from file
551  for (auto & cam_file : cam_files)
552  {
553  std::ifstream ifs(cam_file.c_str());
555  if (!ifs.is_open()) {
556  std::cerr << "Failed to open file " << cam_file << '\n';
557  }
558  else {
559  ifs >> pcam;
560  camlist.push_back(pcam);
561  }
562  }
563  return camlist;
564 }
565 
566 template <class T>
568 {
569  vgl_vector_3d<T> ray1 = cam1.principal_axis();
570  vgl_vector_3d<T> ray2 = cam2.principal_axis();
571 
572  vgl_rotation_3d<T> R(ray1, ray2);
573  double trace = vnl_trace(R.as_matrix());
574  return std::acos((trace-1.0)/2.0); // dist is theta
575 }
576 
577 template <class T>
579 {
581  return out;
582 }
583 
584 template <class T>
586 {
587  vgl_vector_3d<T> p1 = cam1.principal_axis();
588  vgl_vector_3d<T> p2 = cam2.principal_axis();
589 
590  vgl_rotation_3d<T> R(p2, p1);
591  return R;
592 }
593 
594 template <class T>
596  T d_near, T d_far){
597 
598  // normal of top face of the frustum
599  vgl_vector_3d<T> norm = -cam.principal_axis();
600  // get rays through the image corners
603  // image corners
604  vgl_point_2d<T> ul(T(0), T(0));
605  vgl_point_2d<T> ur(T(2.0*pp.x()), T(0));
606  vgl_point_2d<T> lr(T(2.0*pp.x()), T(2.0*pp.y()));
607  vgl_point_2d<T> ll(T(0), T(2.0*pp.y()));
608  std::vector<vgl_ray_3d<T> > corner_rays;
609  corner_rays.push_back(cam.backproject_ray(lr));
610  corner_rays.push_back(cam.backproject_ray(ur));
611  corner_rays.push_back(cam.backproject_ray(ul));
612  corner_rays.push_back(cam.backproject_ray(ll));
613  return vgl_frustum_3d<T>(corner_rays, norm, d_near, d_far);
614 }
615 
616 // Code for easy instantiation.
617 #undef vpgl_PERSPECTIVE_CAMERA_INSTANTIATE
618 #define vpgl_PERSPECTIVE_CAMERA_INSTANTIATE(T) \
619 template class vpgl_perspective_camera<T >; \
620 template bool vpgl_perspective_decomposition(const vnl_matrix_fixed<T,3,4>& camera_matrix, \
621  vpgl_perspective_camera<T >& p_camera ); \
622 template vpgl_perspective_camera<T > vpgl_align_down(const vpgl_perspective_camera<T >& p0, \
623  const vpgl_perspective_camera<T >& p1 ); \
624 template vpgl_perspective_camera<T > vpgl_align_up(const vpgl_perspective_camera<T >& p0, \
625  const vpgl_perspective_camera<T >& p1 ); \
626 template vpgl_perspective_camera<T > postmultiply(const vpgl_perspective_camera<T >& in_cam, \
627  const vgl_h_matrix_3d<T >& euclid_trans); \
628 template double vpgl_persp_cam_distance(const vpgl_perspective_camera<T >& cam1, \
629  const vpgl_perspective_camera<T >& cam2); \
630 template vgl_vector_3d<T> vpgl_persp_cam_base_line_vector(const vpgl_perspective_camera<T>& cam1, \
631  const vpgl_perspective_camera<T>& cam2); \
632 template vgl_rotation_3d<T> vpgl_persp_cam_relative_orientation(const vpgl_perspective_camera<T>& cam1, \
633  const vpgl_perspective_camera<T>& cam2); \
634 template void vrml_write(std::ostream &s, const vpgl_perspective_camera<T >&, double rad); \
635 template std::vector<vpgl_perspective_camera<T > > cameras_from_directory(std::string dir, T); \
636  template vgl_frustum_3d<T> frustum(vpgl_perspective_camera<T> const& cam, T d_near, T d_far); \
637 template std::ostream& operator<<(std::ostream&, const vpgl_perspective_camera<T >&); \
638 template std::istream& operator>>(std::istream&, vpgl_perspective_camera<T >&)
639 
640 
641 #endif // vpgl_perspective_camera_hxx_
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.
vnl_matrix_ref< T > as_ref()
A class for the perspective camera model.
void set_rotation(const vgl_rotation_3d< T > &R)
std::istream & operator >>(std::istream &s, vpgl_perspective_camera< Type > &p)
Read camera from stream.
vgl_point_2d< T > principal_point() const
vnl_matrix_fixed< T, 3, 3 > as_matrix() const
vnl_vector_fixed< T, num_rows > get_column(unsigned col) const
vgl_homg_line_3d_2_points< T > backproject(const vgl_homg_point_2d< T > &image_point) const override
Finite backprojection.
vgl_frustum_3d< T > frustum(vpgl_perspective_camera< T > const &cam, T d_near, T d_far)
compute the frustrum of the camera view cone. The near plane.
vgl_h_matrix_3d & set_translation(T tx, T ty, T tz)
vgl_vector_3d< T > principal_axis() const
Compute the principal axis.
void vrml_write(std::ostream &str, vpgl_perspective_camera< Type > const &p, double rad)
Write vpgl_perspective_camera to a vrml file.
vpgl_perspective_camera< T > vpgl_align_down(const vpgl_perspective_camera< T > &p0, const vpgl_perspective_camera< T > &p1)
Changes the coordinate system of camera p1 such that the same change would transform p0 to K[I|0].
A class representing the "K" matrix of a perspective camera matrix as described in.
T vnl_trace(vnl_matrix< T > const &M)
vgl_vector_3d< Type > direction() const
void set_camera_center(const vgl_point_3d< T > &camera_center)
vnl_matrix< T > const & Q() const
vnl_vector_ref< T > as_ref()
vnl_matrix< T > const & R() const
void save(std::string cam_path) override
Save in ascii format.
const vpgl_calibration_matrix< T > & get_calibration() const
const vgl_rotation_3d< T > & get_rotation() const
vnl_vector_fixed< T, 3 > axis() const
Type z() const
vgl_vector_3d< T > vpgl_persp_cam_base_line_vector(const vpgl_perspective_camera< T > &cam1, const vpgl_perspective_camera< T > &cam2)
#define trace(str)
void set_calibration(const vpgl_calibration_matrix< T > &K)
Setters and getters.
vgl_rotation_3d< T > vpgl_persp_cam_relative_orientation(const vpgl_perspective_camera< T > &cam1, const vpgl_perspective_camera< T > &cam2)
compute rotation such that principal_vector1 = R*principal_vector2.
VNL_EXPORT T vnl_det(T const *row0, T const *row1)
T y() const
double dot(const double *v1, const double *v2, unsigned n)
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.
double angle() const
vnl_matrix< T > extract(unsigned r, unsigned c, unsigned top=0, unsigned left=0) const
vgl_h_matrix_3d & set_rotation_matrix(vnl_matrix_fixed< T, 3, 3 > const &R)
void recompute_matrix()
Recalculate the 3x4 camera matrix from the parameters.
vgl_point_3d< Type > point1() const
double vpgl_persp_cam_distance(const vpgl_perspective_camera< T > &cam1, const vpgl_perspective_camera< T > &cam2)
const vgl_point_3d< T > & get_camera_center() const
bool vpgl_perspective_decomposition(const vnl_matrix_fixed< T, 3, 4 > &camera_matrix, vpgl_perspective_camera< T > &p_camera)
Decompose camera into parameter blocks.
Type w() const
vgl_ray_3d< T > backproject_ray(const vgl_point_2d< T > &image_point) const
Finite ray backprojection.
T x() const
std::ostream & operator<<(std::ostream &s, const vpgl_local_rational_camera< T > &p)
Write to stream.
T z() const
vpgl_perspective_camera< T > vpgl_align_up(const vpgl_perspective_camera< T > &p0, const vpgl_perspective_camera< T > &p1)
Changes the coordinate system of camera p1 such that the same change would transform K[I|0] to p0.
This class implements the perspective camera class as described in Hartley & Zisserman as a finite ca...
vgl_h_matrix_3d & set_identity()
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.
vgl_homg_point_3d< T > get_translation() const
void set(T vx, T vy, T vz)
vpgl_perspective_camera()
Default constructor.
vpgl_proj_camera< T > * clone(void) const override
Clone ‘this’: creation of a new object and initialization.
bool ideal(Type tol=(Type) 0) const
#define l
T dot_product(v const &a, v const &b)
void set_translation(const vgl_vector_3d< T > &t)
void set(T px, T py, T pz)
bool is_euclidean() const
vgl_rotation_3d< T > transpose() const
Type y() const
v & normalize(v &a)
std::vector< vpgl_perspective_camera< T > > cameras_from_directory(std::string dir, T)
Return a list of camera's, loaded from the (name sorted) files from the given directory.
T cross_product(v const &a, v const &b)
vgl_h_matrix_3d< T > get_upper_3x3() const
Type x() const
vgl_vector_3d< T > get_translation() const
v normalized(v const &a)