mapper.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. #ifndef MAPPER_H_
  38. #define MAPPER_H_
  39. #include <opencv2/core.hpp> // Basic OpenCV structures (cv::Mat, Scalar)
  40. #include "map.hpp"
  41. namespace cv {
  42. namespace reg {
  43. //! @addtogroup reg
  44. //! @{
  45. /** @brief Base class for modelling an algorithm for calculating a map
  46. The class is only used to define the common interface for any possible mapping algorithm.
  47. */
  48. class CV_EXPORTS_W Mapper
  49. {
  50. public:
  51. virtual ~Mapper(void) {}
  52. /*
  53. * Calculate mapping between two images
  54. * \param[in] img1 Reference image
  55. * \param[in] img2 Warped image
  56. * \param[in] If present, it is an initial rough estimation that the mapper will try to refine.
  57. * \return Map from img1 to img2, stored in a smart pointer.
  58. */
  59. CV_WRAP virtual cv::Ptr<Map> calculate(InputArray img1, InputArray img2, cv::Ptr<Map> init = cv::Ptr<Map>()) const = 0;
  60. /*
  61. * Returns a map compatible with the Mapper class
  62. * \return Pointer to identity Map
  63. */
  64. CV_WRAP virtual cv::Ptr<Map> getMap() const = 0;
  65. protected:
  66. /*
  67. * Calculates gradient and difference between images
  68. * \param[in] img1 Image one
  69. * \param[in] img2 Image two
  70. * \param[out] Ix Gradient x-coordinate
  71. * \param[out] Iy Gradient y-coordinate
  72. * \param[out] It Difference of images
  73. */
  74. void gradient(const cv::Mat& img1, const cv::Mat& img2,
  75. cv::Mat& Ix, cv::Mat& Iy, cv::Mat& It) const;
  76. /*
  77. * Fills matrices with pixel coordinates of an image
  78. * \param[in] img Image
  79. * \param[out] grid_r Row (y-coordinate)
  80. * \param[out] grid_c Column (x-coordinate)
  81. */
  82. void grid(const Mat& img, Mat& grid_r, Mat& grid_c) const;
  83. /*
  84. * Per-element square of a matrix
  85. * \param[in] mat1 Input matrix
  86. * \return mat1[i,j]^2
  87. */
  88. cv::Mat sqr(const cv::Mat& mat1) const
  89. {
  90. cv::Mat res;
  91. res.create(mat1.size(), mat1.type());
  92. res = mat1.mul(mat1);
  93. return res;
  94. }
  95. };
  96. //! @}
  97. }} // namespace cv::reg
  98. #endif // MAPPER_H_