Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 1 | // Ceres Solver - A fast non-linear least squares minimizer |
| 2 | // Copyright 2010, 2011, 2012 Google Inc. All rights reserved. |
| 3 | // http://code.google.com/p/ceres-solver/ |
| 4 | // |
| 5 | // Redistribution and use in source and binary forms, with or without |
| 6 | // modification, are permitted provided that the following conditions are met: |
| 7 | // |
| 8 | // * Redistributions of source code must retain the above copyright notice, |
| 9 | // this list of conditions and the following disclaimer. |
| 10 | // * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | // this list of conditions and the following disclaimer in the documentation |
| 12 | // and/or other materials provided with the distribution. |
| 13 | // * Neither the name of Google Inc. nor the names of its contributors may be |
| 14 | // used to endorse or promote products derived from this software without |
| 15 | // specific prior written permission. |
| 16 | // |
| 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 27 | // POSSIBILITY OF SUCH DAMAGE. |
| 28 | // |
| 29 | // Author: sameeragarwal@google.com (Sameer Agarwal) |
| 30 | // |
| 31 | // Class for loading and holding in memory bundle adjustment problems |
| 32 | // from the BAL (Bundle Adjustment in the Large) dataset from the |
| 33 | // University of Washington. |
| 34 | // |
| 35 | // For more details see http://grail.cs.washington.edu/projects/bal/ |
| 36 | |
| 37 | #ifndef CERES_EXAMPLES_BAL_PROBLEM_H_ |
| 38 | #define CERES_EXAMPLES_BAL_PROBLEM_H_ |
| 39 | |
| 40 | #include <string> |
| 41 | |
| 42 | namespace ceres { |
| 43 | namespace examples { |
| 44 | |
| 45 | class BALProblem { |
| 46 | public: |
Markus Moll | 2145610 | 2012-08-11 00:26:58 +0200 | [diff] [blame] | 47 | explicit BALProblem(const std::string& filename, bool use_quaternions); |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 48 | ~BALProblem(); |
| 49 | |
Markus Moll | 2145610 | 2012-08-11 00:26:58 +0200 | [diff] [blame] | 50 | void WriteToFile(const std::string& filename) const; |
| 51 | |
Sameer Agarwal | 36a3309 | 2012-08-10 19:52:09 -0700 | [diff] [blame] | 52 | // Move the "center" of the reconstruction to the origin, where the |
| 53 | // center is determined by computing the marginal median of the |
| 54 | // points. The reconstruction is then scaled so that the median |
| 55 | // absolute deviation of the points measured from the origin is |
| 56 | // 100.0. |
| 57 | // |
| 58 | // The reprojection error of the problem remains the same. |
| 59 | void Normalize(); |
| 60 | |
Sameer Agarwal | 5476df5 | 2012-08-09 21:46:19 -0700 | [diff] [blame] | 61 | // Perturb the camera pose and the geometry with random normal |
| 62 | // numbers with corresponding standard deviations. |
| 63 | void Perturb(const double rotation_sigma, |
| 64 | const double translation_sigma, |
| 65 | const double point_sigma); |
| 66 | |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 67 | int camera_block_size() const { return use_quaternions_ ? 10 : 9; } |
| 68 | int point_block_size() const { return 3; } |
| 69 | int num_cameras() const { return num_cameras_; } |
| 70 | int num_points() const { return num_points_; } |
| 71 | int num_observations() const { return num_observations_; } |
| 72 | int num_parameters() const { return num_parameters_; } |
| 73 | const int* point_index() const { return point_index_; } |
| 74 | const int* camera_index() const { return camera_index_; } |
| 75 | const double* observations() const { return observations_; } |
| 76 | const double* parameters() const { return parameters_; } |
| 77 | double* mutable_cameras() { return parameters_; } |
| 78 | double* mutable_points() { |
| 79 | return parameters_ + camera_block_size() * num_cameras_; |
| 80 | } |
| 81 | |
| 82 | private: |
Sameer Agarwal | 36a3309 | 2012-08-10 19:52:09 -0700 | [diff] [blame] | 83 | void CameraToAngleAxisAndCenter(const double* camera, |
| 84 | double* angle_axis, |
| 85 | double* center); |
| 86 | |
| 87 | void AngleAxisAndCenterToCamera(const double* angle_axis, |
| 88 | const double* center, |
| 89 | double* camera); |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 90 | int num_cameras_; |
| 91 | int num_points_; |
| 92 | int num_observations_; |
| 93 | int num_parameters_; |
| 94 | bool use_quaternions_; |
| 95 | |
| 96 | int* point_index_; |
| 97 | int* camera_index_; |
| 98 | double* observations_; |
| 99 | // The parameter vector is laid out as follows |
| 100 | // [camera_1, ..., camera_n, point_1, ..., point_m] |
| 101 | double* parameters_; |
| 102 | }; |
| 103 | |
| 104 | } // namespace examples |
| 105 | } // namespace ceres |
| 106 | |
| 107 | #endif // CERES_EXAMPLES_BAL_PROBLEM_H_ |