9 # include <vcl_msvc_warnings.h> 28 constexpr
int num_vars = 3;
29 const int num_eqs = static_cast<const int>(2 * points.size());
35 for (
unsigned int i = 0; i < points.size(); ++i) {
37 cameras[i].get_translation();
43 cameras[i].get_calibration().map_to_focal_plane(points[i]);
46 A.put(2 * i, 0, rot.
get(0, 0) - pt.
x() * rot.
get(2, 0) );
47 A.put(2 * i, 1, rot.
get(0, 1) - pt.
x() * rot.
get(2, 1) );
48 A.put(2 * i, 2, rot.
get(0, 2) - pt.
x() * rot.
get(2, 2) );
51 A.put(2*i+1, 0, rot.
get(1, 0) - pt.
y() * rot.
get(2, 0) );
52 A.put(2*i+1, 1, rot.
get(1, 1) - pt.
y() * rot.
get(2, 1) );
53 A.put(2*i+1, 2, rot.
get(1, 2) - pt.
y() * rot.
get(2, 2) );
56 b[2*i + 0] = trans.
z() * pt.
x() - trans.
x();
57 b[2*i + 1] = trans.
z() * pt.
y() - trans.
y();
62 vnl_double_3 x = svd.
solve(b);
64 point_3d.
set(x.begin());
68 for (
unsigned int i = 0; i < points.size(); ++i) {
70 vnl_double_3 pp = cameras[i].get_rotation().as_matrix() * x;
72 pp[0] += cameras[i].get_translation().x();
73 pp[1] += cameras[i].get_translation().y();
74 pp[2] += cameras[i].get_translation().z();
76 double dx = pp[0] / pp[2] - points[i].x();
77 double dy = pp[1] / pp[2] - points[i].y();
78 error += dx * dx + dy * dy;
81 return std::sqrt(error / points.size());
Determines the 3D location of a point in world space given the 2D location of the point as seen by a ...
const vnl_matrix< T > as_matrix() const
T get(unsigned r, unsigned c) const
vnl_matrix< T > solve(vnl_matrix< T > const &B) const
This class implements the perspective camera class as described in Hartley & Zisserman as a finite ca...
static double triangulate(const std::vector< vgl_point_2d< double > > &points, const std::vector< vpgl_perspective_camera< double > > &cameras, vgl_point_3d< double > &point_3d)
Calculates the best 3D point corresponding to a set of 2D camera points.
void set(Type px, Type py, Type pz)