optical_flow.hpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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_OPTICAL_FLOW_HPP__
  43. #define __OPENCV_VIDEOSTAB_OPTICAL_FLOW_HPP__
  44. #include "opencv2/core.hpp"
  45. #include "opencv2/opencv_modules.hpp"
  46. #ifdef HAVE_OPENCV_CUDAOPTFLOW
  47. #include "opencv2/cudaoptflow.hpp"
  48. #endif
  49. namespace cv
  50. {
  51. namespace videostab
  52. {
  53. //! @addtogroup videostab
  54. //! @{
  55. class CV_EXPORTS ISparseOptFlowEstimator
  56. {
  57. public:
  58. virtual ~ISparseOptFlowEstimator() {}
  59. virtual void run(
  60. InputArray frame0, InputArray frame1, InputArray points0, InputOutputArray points1,
  61. OutputArray status, OutputArray errors) = 0;
  62. };
  63. class CV_EXPORTS IDenseOptFlowEstimator
  64. {
  65. public:
  66. virtual ~IDenseOptFlowEstimator() {}
  67. virtual void run(
  68. InputArray frame0, InputArray frame1, InputOutputArray flowX, InputOutputArray flowY,
  69. OutputArray errors) = 0;
  70. };
  71. class CV_EXPORTS PyrLkOptFlowEstimatorBase
  72. {
  73. public:
  74. PyrLkOptFlowEstimatorBase() { setWinSize(Size(21, 21)); setMaxLevel(3); }
  75. virtual void setWinSize(Size val) { winSize_ = val; }
  76. virtual Size winSize() const { return winSize_; }
  77. virtual void setMaxLevel(int val) { maxLevel_ = val; }
  78. virtual int maxLevel() const { return maxLevel_; }
  79. virtual ~PyrLkOptFlowEstimatorBase() {}
  80. protected:
  81. Size winSize_;
  82. int maxLevel_;
  83. };
  84. class CV_EXPORTS SparsePyrLkOptFlowEstimator
  85. : public PyrLkOptFlowEstimatorBase, public ISparseOptFlowEstimator
  86. {
  87. public:
  88. virtual void run(
  89. InputArray frame0, InputArray frame1, InputArray points0, InputOutputArray points1,
  90. OutputArray status, OutputArray errors);
  91. };
  92. #ifdef HAVE_OPENCV_CUDAOPTFLOW
  93. class CV_EXPORTS SparsePyrLkOptFlowEstimatorGpu
  94. : public PyrLkOptFlowEstimatorBase, public ISparseOptFlowEstimator
  95. {
  96. public:
  97. SparsePyrLkOptFlowEstimatorGpu();
  98. virtual void run(
  99. InputArray frame0, InputArray frame1, InputArray points0, InputOutputArray points1,
  100. OutputArray status, OutputArray errors);
  101. void run(const cuda::GpuMat &frame0, const cuda::GpuMat &frame1, const cuda::GpuMat &points0, cuda::GpuMat &points1,
  102. cuda::GpuMat &status, cuda::GpuMat &errors);
  103. void run(const cuda::GpuMat &frame0, const cuda::GpuMat &frame1, const cuda::GpuMat &points0, cuda::GpuMat &points1,
  104. cuda::GpuMat &status);
  105. private:
  106. Ptr<cuda::SparsePyrLKOpticalFlow> optFlowEstimator_;
  107. cuda::GpuMat frame0_, frame1_, points0_, points1_, status_, errors_;
  108. };
  109. class CV_EXPORTS DensePyrLkOptFlowEstimatorGpu
  110. : public PyrLkOptFlowEstimatorBase, public IDenseOptFlowEstimator
  111. {
  112. public:
  113. DensePyrLkOptFlowEstimatorGpu();
  114. virtual void run(
  115. InputArray frame0, InputArray frame1, InputOutputArray flowX, InputOutputArray flowY,
  116. OutputArray errors);
  117. private:
  118. Ptr<cuda::DensePyrLKOpticalFlow> optFlowEstimator_;
  119. cuda::GpuMat frame0_, frame1_, flowX_, flowY_, errors_;
  120. };
  121. #endif
  122. //! @}
  123. } // namespace videostab
  124. } // namespace cv
  125. #endif