Go to the documentation of this file.00001
00002 #ifndef vpgl_bundle_adjust_h_
00003 #define vpgl_bundle_adjust_h_
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <vnl/vnl_vector.h>
00016 #include <vgl/vgl_point_2d.h>
00017 #include <vgl/vgl_point_3d.h>
00018 #include <vpgl/vpgl_perspective_camera.h>
00019 #include <vpgl/algo/vpgl_bundle_adjust_lsqr.h>
00020 #include <vcl_vector.h>
00021
00022
00023
00024 class vpgl_bundle_adjust
00025 {
00026 public:
00027
00028 vpgl_bundle_adjust();
00029
00030 ~vpgl_bundle_adjust();
00031
00032 void set_use_m_estimator(bool use_m) { use_m_estimator_ = use_m; }
00033 void set_m_estimator_scale(double scale) { m_estimator_scale_ = scale; }
00034 void set_use_gradient(bool use_gradient) { use_gradient_ = use_gradient; }
00035 void set_self_calibrate(bool self_calibrate) { self_calibrate_ = self_calibrate; }
00036 void set_normalize_data(bool normalize) { normalize_data_ = normalize; }
00037 void set_verbose(bool verbose) { verbose_ = verbose; }
00038 void set_max_iterations(unsigned maxitr) { max_iterations_ = maxitr; }
00039 void set_x_tolerence(double xtol) { x_tol_ = xtol; }
00040 void set_g_tolerence(double gtol) { g_tol_ = gtol; }
00041
00042 void set_epsilon(double eps) { epsilon_ = eps; }
00043
00044
00045 double end_error() const { return end_error_; }
00046
00047 double start_error() const { return start_error_; }
00048
00049 int num_iterations() const { return num_iterations_; }
00050
00051 const vcl_vector<double>& final_weights() const { return weights_; }
00052
00053
00054 const vnl_vector<double>& cam_params() const { return a_; }
00055
00056 const vnl_vector<double>& point_params() const { return b_; }
00057
00058
00059
00060
00061
00062
00063 void depth_reverse(vcl_vector<vpgl_perspective_camera<double> >& cameras,
00064 vcl_vector<vgl_point_3d<double> >& world_points);
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 bool optimize(vcl_vector<vpgl_perspective_camera<double> >& cameras,
00085 vcl_vector<vgl_point_3d<double> >& world_points,
00086 const vcl_vector<vgl_point_2d<double> >& image_points,
00087 const vcl_vector<vcl_vector<bool> >& mask);
00088
00089
00090 static void write_vrml(const vcl_string& filename,
00091 const vcl_vector<vpgl_perspective_camera<double> >& cameras,
00092 const vcl_vector<vgl_point_3d<double> >& world_points);
00093
00094 private:
00095
00096
00097 void normalize_points(vcl_vector<vgl_point_2d<double> >& image_points,
00098 double& nx, double& ny, double& ns);
00099
00100
00101 void reflect_points(const vgl_plane_3d<double>& plane,
00102 vcl_vector<vgl_point_3d<double> >& points);
00103
00104
00105 void rotate_cameras(const vgl_vector_3d<double>& axis,
00106 vcl_vector<vpgl_perspective_camera<double> >& cameras);
00107
00108
00109 vpgl_bundle_adjust_lsqr* ba_func_;
00110
00111 vnl_vector<double> a_;
00112
00113 vnl_vector<double> b_;
00114
00115 vnl_vector<double> c_;
00116
00117 vcl_vector<double> weights_;
00118
00119 bool use_m_estimator_;
00120 double m_estimator_scale_;
00121 bool use_gradient_;
00122 bool self_calibrate_;
00123 bool normalize_data_;
00124 bool verbose_;
00125 unsigned int max_iterations_;
00126 double x_tol_;
00127 double g_tol_;
00128 double epsilon_;
00129
00130 double start_error_;
00131 double end_error_;
00132 int num_iterations_;
00133 };
00134
00135
00136 #endif // vpgl_bundle_adjust_h_