2 #ifndef vpgl_proj_camera_hxx_ 3 #define vpgl_proj_camera_hxx_ 11 # include <vcl_msvc_warnings.h> 28 P_(0,0) =
P_(1,1) =
P_(2,2) = (T)1;
51 P_( cam.get_matrix() ),
61 if ( cached_svd_ !=
nullptr )
delete cached_svd_;
62 cached_svd_ =
nullptr;
70 if ( cached_svd_ !=
nullptr )
delete cached_svd_;
71 cached_svd_ =
nullptr;
90 P_(0,0)*world_point.
x() + P_(0,1)*world_point.
y() +
91 P_(0,2)*world_point.
z() + P_(0,3)*world_point.
w(),
93 P_(1,0)*world_point.
x() + P_(1,1)*world_point.
y() +
94 P_(1,2)*world_point.
z() + P_(1,3)*world_point.
w(),
96 P_(2,0)*world_point.
x() + P_(2,1)*world_point.
y() +
97 P_(2,2)*world_point.
z() + P_(2,3)*world_point.
w() );
108 if (image_point.
ideal(static_cast<T>(1.0e-10)))
111 std::cerr <<
"Warning: projection to ideal image point in vpgl_proj_camera -" 112 <<
" result not valid\n";
115 u = image_point.
x()/image_point.
w();
116 v = image_point.
y()/image_point.
w();
155 if ( wp.
ideal(.000001f) )
168 if ( wp.
ideal(.000001f) ) {
184 world_plane(2), world_plane(3) );
206 if ( cached_svd_ ==
nullptr )
211 if ( cached_svd_->rank() != 3 )
212 std::cerr <<
"vpgl_proj_camera::svd()\n" 213 <<
" Warning: Projection matrix is not rank 3, errors may occur.\n";
222 P_ = new_camera_matrix;
223 if ( cached_svd_ !=
nullptr )
delete cached_svd_;
224 cached_svd_ =
nullptr;
233 if ( cached_svd_ !=
nullptr )
delete cached_svd_;
234 cached_svd_ =
nullptr;
244 template <
class Type>
255 template <
class Type>
269 std::ofstream os(cam_path.c_str());
271 std::cout <<
"unable to open output stream in vpgl_proj_camera<T>::save(.)\n";
274 os << this->get_matrix() <<
'\n';
288 for (
int i = 0; i < 4; i++ ) {
289 for (
int j = 0; j < 3; j++ )
300 std::cerr <<
"fix_cheirality( vpgl_proj_camera<T>& ) not implemented\n";
308 can_cam(0,0) = can_cam(1,1) = can_cam(2,2) = (T)1;
338 for (
int i=0; i<4; i++) {
339 A[0][i] = x1.
x()*P1[2][i] - P1[0][i];
340 A[1][i] = x1.
y()*P1[2][i] - P1[1][i];
341 A[2][i] = x2.
x()*P2[2][i] - P2[0][i];
342 A[3][i] = x2.
y()*P2[2][i] - P2[1][i];
355 std::vector<vnl_matrix_fixed<T,2,3> >
363 Du(0,0) = Du(1,1) = Du(2,2) = 0.0;
364 Du(0,1) = P(0,0)*P(2,1) - P(0,1)*P(2,0);
365 Du(0,2) = P(0,0)*P(2,2) - P(0,2)*P(2,0);
366 Du(1,2) = P(0,1)*P(2,2) - P(0,2)*P(2,1);
367 Du(0,3) = P(0,0)*P(2,3) - P(0,3)*P(2,0);
368 Du(1,3) = P(0,1)*P(2,3) - P(0,3)*P(2,1);
369 Du(2,3) = P(0,2)*P(2,3) - P(0,3)*P(2,2);
375 Dv(0,0) = Dv(1,1) = Dv(2,2) = 0.0;
376 Dv(0,1) = P(1,0)*P(2,1) - P(1,1)*P(2,0);
377 Dv(0,2) = P(1,0)*P(2,2) - P(1,2)*P(2,0);
378 Dv(1,2) = P(1,1)*P(2,2) - P(1,2)*P(2,1);
379 Dv(0,3) = P(1,0)*P(2,3) - P(1,3)*P(2,0);
380 Dv(1,3) = P(1,1)*P(2,3) - P(1,3)*P(2,1);
381 Dv(2,3) = P(1,2)*P(2,3) - P(1,3)*P(2,2);
387 const std::size_t num_pts = pts.size();
388 std::vector<vnl_matrix_fixed<T,2,3> > img_jac(num_pts);
390 for (
unsigned int i=0; i<num_pts; ++i)
408 #undef vpgl_PROJ_CAMERA_INSTANTIATE 409 #define vpgl_PROJ_CAMERA_INSTANTIATE(T) \ 410 template class vpgl_proj_camera<T >; \ 411 template vgl_h_matrix_3d<T > get_canonical_h( vpgl_proj_camera<T >& camera ); \ 412 template void fix_cheirality( vpgl_proj_camera<T >& camera ); \ 413 template void make_canonical( vpgl_proj_camera<T >& camera ); \ 414 template vpgl_proj_camera<T > premultiply( const vpgl_proj_camera<T >& in_camera, \ 415 const vnl_matrix_fixed<T,3,3>& transform ); \ 416 template vpgl_proj_camera<T > postmultiply(const vpgl_proj_camera<T >& in_camera, \ 417 const vnl_matrix_fixed<T,4,4>& transform ); \ 418 template vgl_point_3d<T > triangulate_3d_point(const vpgl_proj_camera<T >& c1, \ 419 const vgl_point_2d<T >& x1, \ 420 const vpgl_proj_camera<T >& c2, \ 421 const vgl_point_2d<T >& x2); \ 422 template std::vector<vnl_matrix_fixed<T,2,3> > \ 423 image_jacobians(const vpgl_proj_camera<T >& camera, \ 424 const std::vector<vgl_point_3d<T > >& pts); \ 425 template std::ostream& operator<<(std::ostream&, const vpgl_proj_camera<T >&); \ 426 template std::istream& operator>>(std::istream&, vpgl_proj_camera<T >&) 428 #endif // vpgl_proj_camera_hxx_
vnl_matrix_ref< T > as_ref()
vnl_svd< T > * svd() const
Get a copy of the svd of the get_matrix.
~vpgl_proj_camera() override
vgl_point_3d< Type > point1() const
vgl_h_matrix_3d< T > get_canonical_h(vpgl_proj_camera< T > &camera)
Return the 3D H-matrix s.t. P * H = [I 0].
std::istream & operator>>(std::istream &is, vpgl_local_rational_camera< T > &p)
Read from stream.
bool ideal(T tol=(T) 0) const
vgl_point_3d< Type > point2() const
vnl_matrix_fixed & set_row(unsigned i, T const *v)
vnl_matrix_fixed< T, 3, 4 > P_
The internal representation of the get_matrix.
void project(const T x, const T y, const T z, T &u, T &v) const override
Projection from base class.
virtual vpgl_proj_camera< T > * clone(void) const
Clone ‘this’: creation of a new object and initialization.
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.
void fix_cheirality(vpgl_proj_camera< T > &)
Scale the camera matrix so determinant of first 3x3 is 1.
virtual vgl_homg_line_3d_2_points< T > backproject(const vgl_homg_point_2d< T > &image_point) const
Find the 3d ray that goes through the camera center and the provided image point.
vgl_point_3d< Type > point_t(const double t) const
virtual vgl_homg_point_3d< T > camera_center() const
Find the 3d coordinates of the center of the camera.
vgl_point_3d< T > triangulate_3d_point(const vpgl_proj_camera< T > &c1, const vgl_point_2d< T > &x1, const vpgl_proj_camera< T > &c2, const vgl_point_2d< T > &x2)
Linearly intersect two camera rays to form a 3-d point.
std::ostream & operator<<(std::ostream &s, const vpgl_local_rational_camera< T > &p)
Write to stream.
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.
const vpgl_proj_camera< T > & operator=(const vpgl_proj_camera &cam)
Assignment.
A camera model using the standard 3x4 matrix representation.
std::vector< vnl_matrix_fixed< T, 2, 3 > > image_jacobians(const vpgl_proj_camera< T > &camera, const std::vector< vgl_point_3d< T > > &pts)
Compute the image projection Jacobians at each point.
const vnl_matrix_fixed< T, 3, 4 > & get_matrix() const
Return a copy of the camera matrix.
void make_canonical(vpgl_proj_camera< T > &camera)
Set the camera matrix to [ I | 0 ].
virtual void save(std::string cam_path)
Save in ascii format.
bool ideal(Type tol=(Type) 0) const
T dot_product(v const &a, v const &b)
vpgl_proj_camera< T > premultiply(const vpgl_proj_camera< T > &in_camera, const vnl_matrix_fixed< T, 3, 3 > &transform)
Pre-multiply this projection matrix with a 2-d projective transform.
vgl_point_3d< Type > point() const
vpgl_proj_camera< T > postmultiply(const vpgl_proj_camera< T > &in_camera, const vnl_matrix_fixed< T, 4, 4 > &transform)
Post-multiply this projection matrix with a 3-d projective transform.
vnl_vector_fixed< T, num_cols > get_row(unsigned row) const
vpgl_proj_camera()
Default constructor makes an identity camera.