Joe Verbout
/
main
opencv on mbed
opencv2/videostab/fast_marching.hpp@0:ea44dc9ed014, 2016-03-31 (annotated)
- Committer:
- joeverbout
- Date:
- Thu Mar 31 21:16:38 2016 +0000
- Revision:
- 0:ea44dc9ed014
OpenCV on mbed attempt
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
joeverbout | 0:ea44dc9ed014 | 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// |
joeverbout | 0:ea44dc9ed014 | 2 | // |
joeverbout | 0:ea44dc9ed014 | 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. |
joeverbout | 0:ea44dc9ed014 | 4 | // |
joeverbout | 0:ea44dc9ed014 | 5 | // By downloading, copying, installing or using the software you agree to this license. |
joeverbout | 0:ea44dc9ed014 | 6 | // If you do not agree to this license, do not download, install, |
joeverbout | 0:ea44dc9ed014 | 7 | // copy or use the software. |
joeverbout | 0:ea44dc9ed014 | 8 | // |
joeverbout | 0:ea44dc9ed014 | 9 | // |
joeverbout | 0:ea44dc9ed014 | 10 | // License Agreement |
joeverbout | 0:ea44dc9ed014 | 11 | // For Open Source Computer Vision Library |
joeverbout | 0:ea44dc9ed014 | 12 | // |
joeverbout | 0:ea44dc9ed014 | 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. |
joeverbout | 0:ea44dc9ed014 | 14 | // Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. |
joeverbout | 0:ea44dc9ed014 | 15 | // Third party copyrights are property of their respective owners. |
joeverbout | 0:ea44dc9ed014 | 16 | // |
joeverbout | 0:ea44dc9ed014 | 17 | // Redistribution and use in source and binary forms, with or without modification, |
joeverbout | 0:ea44dc9ed014 | 18 | // are permitted provided that the following conditions are met: |
joeverbout | 0:ea44dc9ed014 | 19 | // |
joeverbout | 0:ea44dc9ed014 | 20 | // * Redistribution's of source code must retain the above copyright notice, |
joeverbout | 0:ea44dc9ed014 | 21 | // this list of conditions and the following disclaimer. |
joeverbout | 0:ea44dc9ed014 | 22 | // |
joeverbout | 0:ea44dc9ed014 | 23 | // * Redistribution's in binary form must reproduce the above copyright notice, |
joeverbout | 0:ea44dc9ed014 | 24 | // this list of conditions and the following disclaimer in the documentation |
joeverbout | 0:ea44dc9ed014 | 25 | // and/or other materials provided with the distribution. |
joeverbout | 0:ea44dc9ed014 | 26 | // |
joeverbout | 0:ea44dc9ed014 | 27 | // * The name of the copyright holders may not be used to endorse or promote products |
joeverbout | 0:ea44dc9ed014 | 28 | // derived from this software without specific prior written permission. |
joeverbout | 0:ea44dc9ed014 | 29 | // |
joeverbout | 0:ea44dc9ed014 | 30 | // This software is provided by the copyright holders and contributors "as is" and |
joeverbout | 0:ea44dc9ed014 | 31 | // any express or implied warranties, including, but not limited to, the implied |
joeverbout | 0:ea44dc9ed014 | 32 | // warranties of merchantability and fitness for a particular purpose are disclaimed. |
joeverbout | 0:ea44dc9ed014 | 33 | // In no event shall the Intel Corporation or contributors be liable for any direct, |
joeverbout | 0:ea44dc9ed014 | 34 | // indirect, incidental, special, exemplary, or consequential damages |
joeverbout | 0:ea44dc9ed014 | 35 | // (including, but not limited to, procurement of substitute goods or services; |
joeverbout | 0:ea44dc9ed014 | 36 | // loss of use, data, or profits; or business interruption) however caused |
joeverbout | 0:ea44dc9ed014 | 37 | // and on any theory of liability, whether in contract, strict liability, |
joeverbout | 0:ea44dc9ed014 | 38 | // or tort (including negligence or otherwise) arising in any way out of |
joeverbout | 0:ea44dc9ed014 | 39 | // the use of this software, even if advised of the possibility of such damage. |
joeverbout | 0:ea44dc9ed014 | 40 | // |
joeverbout | 0:ea44dc9ed014 | 41 | //M*/ |
joeverbout | 0:ea44dc9ed014 | 42 | |
joeverbout | 0:ea44dc9ed014 | 43 | #ifndef __OPENCV_VIDEOSTAB_FAST_MARCHING_HPP__ |
joeverbout | 0:ea44dc9ed014 | 44 | #define __OPENCV_VIDEOSTAB_FAST_MARCHING_HPP__ |
joeverbout | 0:ea44dc9ed014 | 45 | |
joeverbout | 0:ea44dc9ed014 | 46 | #include <cmath> |
joeverbout | 0:ea44dc9ed014 | 47 | #include <queue> |
joeverbout | 0:ea44dc9ed014 | 48 | #include <algorithm> |
joeverbout | 0:ea44dc9ed014 | 49 | #include "opencv2/core.hpp" |
joeverbout | 0:ea44dc9ed014 | 50 | |
joeverbout | 0:ea44dc9ed014 | 51 | namespace cv |
joeverbout | 0:ea44dc9ed014 | 52 | { |
joeverbout | 0:ea44dc9ed014 | 53 | namespace videostab |
joeverbout | 0:ea44dc9ed014 | 54 | { |
joeverbout | 0:ea44dc9ed014 | 55 | |
joeverbout | 0:ea44dc9ed014 | 56 | //! @addtogroup videostab_marching |
joeverbout | 0:ea44dc9ed014 | 57 | //! @{ |
joeverbout | 0:ea44dc9ed014 | 58 | |
joeverbout | 0:ea44dc9ed014 | 59 | /** @brief Describes the Fast Marching Method implementation. |
joeverbout | 0:ea44dc9ed014 | 60 | |
joeverbout | 0:ea44dc9ed014 | 61 | See http://iwi.eldoc.ub.rug.nl/FILES/root/2004/JGraphToolsTelea/2004JGraphToolsTelea.pdf |
joeverbout | 0:ea44dc9ed014 | 62 | */ |
joeverbout | 0:ea44dc9ed014 | 63 | class CV_EXPORTS FastMarchingMethod |
joeverbout | 0:ea44dc9ed014 | 64 | { |
joeverbout | 0:ea44dc9ed014 | 65 | public: |
joeverbout | 0:ea44dc9ed014 | 66 | FastMarchingMethod() : inf_(1e6f) {} |
joeverbout | 0:ea44dc9ed014 | 67 | |
joeverbout | 0:ea44dc9ed014 | 68 | /** @brief Template method that runs the Fast Marching Method. |
joeverbout | 0:ea44dc9ed014 | 69 | |
joeverbout | 0:ea44dc9ed014 | 70 | @param mask Image mask. 0 value indicates that the pixel value must be inpainted, 255 indicates |
joeverbout | 0:ea44dc9ed014 | 71 | that the pixel value is known, other values aren't acceptable. |
joeverbout | 0:ea44dc9ed014 | 72 | @param inpaint Inpainting functor that overloads void operator ()(int x, int y). |
joeverbout | 0:ea44dc9ed014 | 73 | @return Inpainting functor. |
joeverbout | 0:ea44dc9ed014 | 74 | */ |
joeverbout | 0:ea44dc9ed014 | 75 | template <typename Inpaint> |
joeverbout | 0:ea44dc9ed014 | 76 | Inpaint run(const Mat &mask, Inpaint inpaint); |
joeverbout | 0:ea44dc9ed014 | 77 | |
joeverbout | 0:ea44dc9ed014 | 78 | /** |
joeverbout | 0:ea44dc9ed014 | 79 | @return Distance map that's created during working of the method. |
joeverbout | 0:ea44dc9ed014 | 80 | */ |
joeverbout | 0:ea44dc9ed014 | 81 | Mat distanceMap() const { return dist_; } |
joeverbout | 0:ea44dc9ed014 | 82 | |
joeverbout | 0:ea44dc9ed014 | 83 | private: |
joeverbout | 0:ea44dc9ed014 | 84 | enum { INSIDE = 0, BAND = 1, KNOWN = 255 }; |
joeverbout | 0:ea44dc9ed014 | 85 | |
joeverbout | 0:ea44dc9ed014 | 86 | struct DXY |
joeverbout | 0:ea44dc9ed014 | 87 | { |
joeverbout | 0:ea44dc9ed014 | 88 | float dist; |
joeverbout | 0:ea44dc9ed014 | 89 | int x, y; |
joeverbout | 0:ea44dc9ed014 | 90 | |
joeverbout | 0:ea44dc9ed014 | 91 | DXY() : dist(0), x(0), y(0) {} |
joeverbout | 0:ea44dc9ed014 | 92 | DXY(float _dist, int _x, int _y) : dist(_dist), x(_x), y(_y) {} |
joeverbout | 0:ea44dc9ed014 | 93 | bool operator <(const DXY &dxy) const { return dist < dxy.dist; } |
joeverbout | 0:ea44dc9ed014 | 94 | }; |
joeverbout | 0:ea44dc9ed014 | 95 | |
joeverbout | 0:ea44dc9ed014 | 96 | float solve(int x1, int y1, int x2, int y2) const; |
joeverbout | 0:ea44dc9ed014 | 97 | int& indexOf(const DXY &dxy) { return index_(dxy.y, dxy.x); } |
joeverbout | 0:ea44dc9ed014 | 98 | |
joeverbout | 0:ea44dc9ed014 | 99 | void heapUp(int idx); |
joeverbout | 0:ea44dc9ed014 | 100 | void heapDown(int idx); |
joeverbout | 0:ea44dc9ed014 | 101 | void heapAdd(const DXY &dxy); |
joeverbout | 0:ea44dc9ed014 | 102 | void heapRemoveMin(); |
joeverbout | 0:ea44dc9ed014 | 103 | |
joeverbout | 0:ea44dc9ed014 | 104 | float inf_; |
joeverbout | 0:ea44dc9ed014 | 105 | |
joeverbout | 0:ea44dc9ed014 | 106 | cv::Mat_<uchar> flag_; // flag map |
joeverbout | 0:ea44dc9ed014 | 107 | cv::Mat_<float> dist_; // distance map |
joeverbout | 0:ea44dc9ed014 | 108 | |
joeverbout | 0:ea44dc9ed014 | 109 | cv::Mat_<int> index_; // index of point in the narrow band |
joeverbout | 0:ea44dc9ed014 | 110 | std::vector<DXY> narrowBand_; // narrow band heap |
joeverbout | 0:ea44dc9ed014 | 111 | int size_; // narrow band size |
joeverbout | 0:ea44dc9ed014 | 112 | }; |
joeverbout | 0:ea44dc9ed014 | 113 | |
joeverbout | 0:ea44dc9ed014 | 114 | //! @} |
joeverbout | 0:ea44dc9ed014 | 115 | |
joeverbout | 0:ea44dc9ed014 | 116 | } // namespace videostab |
joeverbout | 0:ea44dc9ed014 | 117 | } // namespace cv |
joeverbout | 0:ea44dc9ed014 | 118 | |
joeverbout | 0:ea44dc9ed014 | 119 | #include "fast_marching_inl.hpp" |
joeverbout | 0:ea44dc9ed014 | 120 | |
joeverbout | 0:ea44dc9ed014 | 121 | #endif |
joeverbout | 0:ea44dc9ed014 | 122 |