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 43 #ifndef __OPENCV_VIDEOSTAB_MOTION_CORE_HPP__ 44 #define __OPENCV_VIDEOSTAB_MOTION_CORE_HPP__ 45 46 #include <cmath> 47 #include "opencv2/core.hpp" 48 49 namespace cv 50 { 51 namespace videostab 52 { 53 54 //! @addtogroup videostab_motion 55 //! @{ 56 57 /** @brief Describes motion model between two point clouds. 58 */ 59 enum MotionModel 60 { 61 MM_TRANSLATION = 0, 62 MM_TRANSLATION_AND_SCALE = 1, 63 MM_ROTATION = 2, 64 MM_RIGID = 3, 65 MM_SIMILARITY = 4, 66 MM_AFFINE = 5, 67 MM_HOMOGRAPHY = 6, 68 MM_UNKNOWN = 7 69 }; 70 71 /** @brief Describes RANSAC method parameters. 72 */ 73 struct CV_EXPORTS RansacParams 74 { 75 int size; //!< subset size 76 float thresh; //!< max error to classify as inlier 77 float eps; //!< max outliers ratio 78 float prob; //!< probability of success 79 80 RansacParams() : size(0), thresh(0), eps(0), prob(0) {} 81 /** @brief Constructor 82 @param size Subset size. 83 @param thresh Maximum re-projection error value to classify as inlier. 84 @param eps Maximum ratio of incorrect correspondences. 85 @param prob Required success probability. 86 */ 87 RansacParams(int size, float thresh, float eps, float prob); 88 89 /** 90 @return Number of iterations that'll be performed by RANSAC method. 91 */ 92 int niters() const 93 { 94 return static_cast<int>( 95 std::ceil(std::log(1 - prob) / std::log(1 - std::pow(1 - eps, size)))); 96 } 97 98 /** 99 @param model Motion model. See cv::videostab::MotionModel. 100 @return Default RANSAC method parameters for the given motion model. 101 */ 102 static RansacParams default2dMotion(MotionModel model) 103 { 104 CV_Assert(model < MM_UNKNOWN); 105 if (model == MM_TRANSLATION) 106 return RansacParams(1, 0.5f, 0.5f, 0.99f); 107 if (model == MM_TRANSLATION_AND_SCALE) 108 return RansacParams(2, 0.5f, 0.5f, 0.99f); 109 if (model == MM_ROTATION) 110 return RansacParams(1, 0.5f, 0.5f, 0.99f); 111 if (model == MM_RIGID) 112 return RansacParams(2, 0.5f, 0.5f, 0.99f); 113 if (model == MM_SIMILARITY) 114 return RansacParams(2, 0.5f, 0.5f, 0.99f); 115 if (model == MM_AFFINE) 116 return RansacParams(3, 0.5f, 0.5f, 0.99f); 117 return RansacParams(4, 0.5f, 0.5f, 0.99f); 118 } 119 }; 120 121 inline RansacParams::RansacParams(int _size, float _thresh, float _eps, float _prob) 122 : size(_size), thresh(_thresh), eps(_eps), prob(_prob) {} 123 124 //! @} 125 126 } // namespace videostab 127 } // namespace cv 128 129 #endif 130