motion_core.hpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*M///////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
  4. //
  5. // By downloading, copying, installing or using the software you agree to this license.
  6. // If you do not agree to this license, do not download, install,
  7. // copy or use the software.
  8. //
  9. //
  10. // License Agreement
  11. // For Open Source Computer Vision Library
  12. //
  13. // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
  14. // Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved.
  15. // Third party copyrights are property of their respective owners.
  16. //
  17. // Redistribution and use in source and binary forms, with or without modification,
  18. // are permitted provided that the following conditions are met:
  19. //
  20. // * Redistribution's of source code must retain the above copyright notice,
  21. // this list of conditions and the following disclaimer.
  22. //
  23. // * Redistribution's in binary form must reproduce the above copyright notice,
  24. // this list of conditions and the following disclaimer in the documentation
  25. // and/or other materials provided with the distribution.
  26. //
  27. // * The name of the copyright holders may not be used to endorse or promote products
  28. // derived from this software without specific prior written permission.
  29. //
  30. // This software is provided by the copyright holders and contributors "as is" and
  31. // any express or implied warranties, including, but not limited to, the implied
  32. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  33. // In no event shall the Intel Corporation or contributors be liable for any direct,
  34. // indirect, incidental, special, exemplary, or consequential damages
  35. // (including, but not limited to, procurement of substitute goods or services;
  36. // loss of use, data, or profits; or business interruption) however caused
  37. // and on any theory of liability, whether in contract, strict liability,
  38. // or tort (including negligence or otherwise) arising in any way out of
  39. // the use of this software, even if advised of the possibility of such damage.
  40. //
  41. //M*/
  42. #ifndef OPENCV_VIDEOSTAB_MOTION_CORE_HPP
  43. #define OPENCV_VIDEOSTAB_MOTION_CORE_HPP
  44. #include <cmath>
  45. #include "opencv2/core.hpp"
  46. namespace cv
  47. {
  48. namespace videostab
  49. {
  50. //! @addtogroup videostab_motion
  51. //! @{
  52. /** @brief Describes motion model between two point clouds.
  53. */
  54. enum MotionModel
  55. {
  56. MM_TRANSLATION = 0,
  57. MM_TRANSLATION_AND_SCALE = 1,
  58. MM_ROTATION = 2,
  59. MM_RIGID = 3,
  60. MM_SIMILARITY = 4,
  61. MM_AFFINE = 5,
  62. MM_HOMOGRAPHY = 6,
  63. MM_UNKNOWN = 7
  64. };
  65. /** @brief Describes RANSAC method parameters.
  66. */
  67. struct CV_EXPORTS RansacParams
  68. {
  69. int size; //!< subset size
  70. float thresh; //!< max error to classify as inlier
  71. float eps; //!< max outliers ratio
  72. float prob; //!< probability of success
  73. RansacParams() : size(0), thresh(0), eps(0), prob(0) {}
  74. /** @brief Constructor
  75. @param size Subset size.
  76. @param thresh Maximum re-projection error value to classify as inlier.
  77. @param eps Maximum ratio of incorrect correspondences.
  78. @param prob Required success probability.
  79. */
  80. RansacParams(int size, float thresh, float eps, float prob);
  81. /**
  82. @return Number of iterations that'll be performed by RANSAC method.
  83. */
  84. int niters() const
  85. {
  86. return static_cast<int>(
  87. std::ceil(std::log(1 - prob) / std::log(1 - std::pow(1 - eps, size))));
  88. }
  89. /**
  90. @param model Motion model. See cv::videostab::MotionModel.
  91. @return Default RANSAC method parameters for the given motion model.
  92. */
  93. static RansacParams default2dMotion(MotionModel model)
  94. {
  95. CV_Assert(model < MM_UNKNOWN);
  96. if (model == MM_TRANSLATION)
  97. return RansacParams(1, 0.5f, 0.5f, 0.99f);
  98. if (model == MM_TRANSLATION_AND_SCALE)
  99. return RansacParams(2, 0.5f, 0.5f, 0.99f);
  100. if (model == MM_ROTATION)
  101. return RansacParams(1, 0.5f, 0.5f, 0.99f);
  102. if (model == MM_RIGID)
  103. return RansacParams(2, 0.5f, 0.5f, 0.99f);
  104. if (model == MM_SIMILARITY)
  105. return RansacParams(2, 0.5f, 0.5f, 0.99f);
  106. if (model == MM_AFFINE)
  107. return RansacParams(3, 0.5f, 0.5f, 0.99f);
  108. return RansacParams(4, 0.5f, 0.5f, 0.99f);
  109. }
  110. };
  111. inline RansacParams::RansacParams(int _size, float _thresh, float _eps, float _prob)
  112. : size(_size), thresh(_thresh), eps(_eps), prob(_prob) {}
  113. //! @}
  114. } // namespace videostab
  115. } // namespace cv
  116. #endif