|
| 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 | +// Copyright (C) 2013, Alfonso Sanchez-Beato, all rights reserved. |
| 10 | +// Third party copyrights are property of their respective owners. |
| 11 | +// |
| 12 | +// Redistribution and use in source and binary forms, with or without modification, |
| 13 | +// are permitted provided that the following conditions are met: |
| 14 | +// |
| 15 | +// * Redistribution's of source code must retain the above copyright notice, |
| 16 | +// this list of conditions and the following disclaimer. |
| 17 | +// |
| 18 | +// * Redistribution's in binary form must reproduce the above copyright notice, |
| 19 | +// this list of conditions and the following disclaimer in the documentation |
| 20 | +// and/or other materials provided with the distribution. |
| 21 | +// |
| 22 | +// * The name of the copyright holders may not be used to endorse or promote products |
| 23 | +// derived from this software without specific prior written permission. |
| 24 | +// |
| 25 | +// This software is provided by the copyright holders and contributors "as is" and |
| 26 | +// any express or implied warranties, including, but not limited to, the implied |
| 27 | +// warranties of merchantability and fitness for a particular purpose are disclaimed. |
| 28 | +// In no event shall the contributors be liable for any direct, |
| 29 | +// indirect, incidental, special, exemplary, or consequential damages |
| 30 | +// (including, but not limited to, procurement of substitute goods or services; |
| 31 | +// loss of use, data, or profits; or business interruption) however caused |
| 32 | +// and on any theory of liability, whether in contract, strict liability, |
| 33 | +// or tort (including negligence or otherwise) arising in any way out of |
| 34 | +// the use of this software, even if advised of the possibility of such damage. |
| 35 | +// |
| 36 | +//M*/ |
| 37 | + |
| 38 | +#ifndef MAPPER_H_ |
| 39 | +#define MAPPER_H_ |
| 40 | + |
| 41 | +#include <opencv2/core.hpp> // Basic OpenCV structures (cv::Mat, Scalar) |
| 42 | +#include "map.hpp" |
| 43 | + |
| 44 | +namespace cv { |
| 45 | +namespace reg { |
| 46 | + |
| 47 | +/* |
| 48 | + * Encapsulates ways of calculating mappings between two images |
| 49 | + */ |
| 50 | +class CV_EXPORTS Mapper |
| 51 | +{ |
| 52 | +public: |
| 53 | + virtual ~Mapper(void) {} |
| 54 | + |
| 55 | + /* |
| 56 | + * Calculate mapping between two images |
| 57 | + * \param[in] img1 Reference image |
| 58 | + * \param[in] img2 Warped image |
| 59 | + * \param[in,out] res Map from img1 to img2, stored in a smart pointer. If present as input, |
| 60 | + * it is an initial rough estimation that the mapper will try to refine. |
| 61 | + */ |
| 62 | + virtual void calculate(const cv::Mat& img1, const cv::Mat& img2, cv::Ptr<Map>& res) const = 0; |
| 63 | + |
| 64 | + /* |
| 65 | + * Returns a map compatible with the Mapper class |
| 66 | + * \return Pointer to identity Map |
| 67 | + */ |
| 68 | + virtual cv::Ptr<Map> getMap(void) const = 0; |
| 69 | + |
| 70 | +protected: |
| 71 | + /* |
| 72 | + * Calculates gradient and difference between images |
| 73 | + * \param[in] img1 Image one |
| 74 | + * \param[in] img2 Image two |
| 75 | + * \param[out] Ix Gradient x-coordinate |
| 76 | + * \param[out] Iy Gradient y-coordinate |
| 77 | + * \param[out] It Difference of images |
| 78 | + */ |
| 79 | + void gradient(const cv::Mat& img1, const cv::Mat& img2, |
| 80 | + cv::Mat& Ix, cv::Mat& Iy, cv::Mat& It) const; |
| 81 | + |
| 82 | + /* |
| 83 | + * Fills matrices with pixel coordinates of an image |
| 84 | + * \param[in] img Image |
| 85 | + * \param[out] grid_r Row (y-coordinate) |
| 86 | + * \param[out] grid_c Column (x-coordinate) |
| 87 | + */ |
| 88 | + void grid(const Mat& img, Mat& grid_r, Mat& grid_c) const; |
| 89 | + |
| 90 | + /* |
| 91 | + * Per-element square of a matrix |
| 92 | + * \param[in] mat1 Input matrix |
| 93 | + * \return mat1[i,j]^2 |
| 94 | + */ |
| 95 | + cv::Mat sqr(const cv::Mat& mat1) const |
| 96 | + { |
| 97 | + cv::Mat res; |
| 98 | + res.create(mat1.size(), mat1.type()); |
| 99 | + res = mat1.mul(mat1); |
| 100 | + return res; |
| 101 | + } |
| 102 | +}; |
| 103 | + |
| 104 | + |
| 105 | +}} // namespace cv::reg |
| 106 | + |
| 107 | +#endif // MAPPER_H_ |
| 108 | + |
0 commit comments