5 # include <vcl_msvc_warnings.h> 33 const double u0 = principal_point.
x();
34 const double v0 = principal_point.
y();
38 std::cerr <<
"compute::natural input homography is an inversion" << std::endl;
43 double a = - H[2][0] * H[2][1]
44 + H[2][1] * H[2][1] - H[2][0] * H[2][0];
46 double b = H[0][0] * ( H[0][1] - u0 * H[2][1] )
47 + H[1][0] * ( H[1][1] - v0 * H[2][1] )
48 + H[2][0] * ( -u0 * H[0][1] - v0 * H[1][1] )
49 + H[0][0] * ( H[0][0] - u0 * H[2][0] )
50 + H[1][0] * ( H[1][0] - v0 * H[2][0] )
51 + H[2][0] * ( - u0 * H[0][0] - v0 * H[1][0] )
52 - H[0][1] * ( H[0][1] - u0 * H[2][1] )
53 - H[1][1] * ( H[1][1] - v0 * H[2][1] )
54 - H[2][1] * ( - u0 * H[0][1] - v0 * H[1][1] );
60 double f2 = x - u0 * u0 - v0 * v0;
63 std::cout <<
"suspicious square focal length: " << f2 << std::endl;
67 double f = std::sqrt( f2 );
81 if ( image_pts.size() != ground_pts.size() )
83 std::cerr <<
"number of image and ground points must be the same" << std::endl;
87 if ( image_pts.size() < 4 )
89 std::cerr <<
"at least four point correspondences are required" << std::endl;
95 std::vector< vgl_homg_point_2d<double> > homg_image_pts;
96 std::vector< vgl_homg_point_2d<double> > homg_ground_pts;
97 for (
unsigned int k = 0; k < image_pts.size(); ++k )
99 homg_image_pts.emplace_back( image_pts[k] );
100 homg_ground_pts.emplace_back( ground_pts[k] );
107 std::cerr <<
"failed to compute homography" << std::endl;
vnl_matrix_fixed< double, 3, 3 > const & get_matrix() const
Computes a camera calibration matrix from points on a 3D world plane.
static bool natural(const vgl_h_matrix_2d< double > &homography, const vgl_point_2d< double > &principal_point, vpgl_calibration_matrix< double > &K)
Computes the calibration matrix for a natural camera (zero skew, square pixels).
VNL_EXPORT T vnl_det(T const *row0, T const *row1)
bool optimize(std::vector< vgl_homg_point_2d< double > > const &points1, std::vector< vgl_homg_point_2d< double > > const &points2, vgl_h_matrix_2d< double > &H)