test_simple_pipeline.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Software License Agreement (BSD License)
  3. *
  4. * Copyright (c) 2009, Willow Garage, Inc.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * * Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * * Redistributions in binary form must reproduce the above
  14. * copyright notice, this list of conditions and the following
  15. * disclaimer in the documentation and/or other materials provided
  16. * with the distribution.
  17. * * Neither the name of Willow Garage, Inc. nor the names of its
  18. * contributors may be used to endorse or promote products derived
  19. * from this software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  28. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. */
  35. #if CERES_FOUND
  36. #include "test_precomp.hpp"
  37. #include <opencv2/sfm/simple_pipeline.hpp>
  38. namespace opencv_test { namespace {
  39. const string SFM_DIR = "sfm";
  40. const string TRACK_FILENAME = "backyard_tracks.txt";
  41. TEST(Sfm_simple_pipeline, backyard)
  42. {
  43. string trackFilename =
  44. string(TS::ptr()->get_data_path()) + SFM_DIR + "/" + TRACK_FILENAME;
  45. // Get tracks from file: check backyard.blend file
  46. std::vector<Mat> points2d;
  47. parser_2D_tracks( trackFilename, points2d );
  48. // Initial reconstruction
  49. int keyframe1 = 1, keyframe2 = 30;
  50. // Camera data
  51. double focal_length = 860.986572265625; // f = 24mm (checked debugging blender)
  52. double principal_x = 400, principal_y = 225, k1 = -0.158, k2 = 0.131, k3 = 0;
  53. int refine_intrinsics = SFM_REFINE_FOCAL_LENGTH | SFM_REFINE_PRINCIPAL_POINT | SFM_REFINE_RADIAL_DISTORTION_K1 | SFM_REFINE_RADIAL_DISTORTION_K2;
  54. int select_keyframes = 0; // disable automatic keyframes selection
  55. int verbosity_level = -1; // mute logs
  56. libmv_CameraIntrinsicsOptions camera_instrinsic_options =
  57. libmv_CameraIntrinsicsOptions(SFM_DISTORTION_MODEL_POLYNOMIAL,
  58. focal_length, principal_x, principal_y,
  59. k1, k2, k3);
  60. libmv_ReconstructionOptions reconstruction_options(keyframe1, keyframe2, refine_intrinsics, select_keyframes, verbosity_level);
  61. Ptr<SFMLibmvEuclideanReconstruction> euclidean_reconstruction =
  62. SFMLibmvEuclideanReconstruction::create(camera_instrinsic_options, reconstruction_options);
  63. // Run reconstruction pipeline
  64. euclidean_reconstruction->run(points2d);
  65. double error = euclidean_reconstruction->getError();
  66. //cout << "euclidean_reconstruction error = " << error << endl;
  67. EXPECT_LE( error, 1.4 ); // actually 1.38671
  68. // UPDATE: 1.38894
  69. }
  70. }} // namespace
  71. #endif /* CERES_FOUND */