cudabgsegm.hpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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, 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_CUDABGSEGM_HPP
  43. #define OPENCV_CUDABGSEGM_HPP
  44. #ifndef __cplusplus
  45. # error cudabgsegm.hpp header must be compiled as C++
  46. #endif
  47. #include "opencv2/core/cuda.hpp"
  48. #include "opencv2/video/background_segm.hpp"
  49. /**
  50. @addtogroup cuda
  51. @{
  52. @defgroup cudabgsegm Background Segmentation
  53. @}
  54. */
  55. namespace cv { namespace cuda {
  56. //! @addtogroup cudabgsegm
  57. //! @{
  58. ////////////////////////////////////////////////////
  59. // MOG
  60. /** @brief Gaussian Mixture-based Background/Foreground Segmentation Algorithm.
  61. The class discriminates between foreground and background pixels by building and maintaining a model
  62. of the background. Any pixel which does not fit this model is then deemed to be foreground. The
  63. class implements algorithm described in @cite MOG2001 .
  64. @sa BackgroundSubtractorMOG
  65. @note
  66. - An example on gaussian mixture based background/foreground segmantation can be found at
  67. opencv_source_code/samples/gpu/bgfg_segm.cpp
  68. */
  69. class CV_EXPORTS_W BackgroundSubtractorMOG : public cv::BackgroundSubtractor
  70. {
  71. public:
  72. using cv::BackgroundSubtractor::apply;
  73. CV_WRAP virtual void apply(InputArray image, OutputArray fgmask, double learningRate, Stream& stream) = 0;
  74. using cv::BackgroundSubtractor::getBackgroundImage;
  75. virtual void getBackgroundImage(OutputArray backgroundImage, Stream& stream) const = 0;
  76. CV_WRAP inline void getBackgroundImage(CV_OUT GpuMat& backgroundImage, Stream& stream) {
  77. getBackgroundImage(OutputArray(backgroundImage), stream);
  78. }
  79. CV_WRAP virtual int getHistory() const = 0;
  80. CV_WRAP virtual void setHistory(int nframes) = 0;
  81. CV_WRAP virtual int getNMixtures() const = 0;
  82. CV_WRAP virtual void setNMixtures(int nmix) = 0;
  83. CV_WRAP virtual double getBackgroundRatio() const = 0;
  84. CV_WRAP virtual void setBackgroundRatio(double backgroundRatio) = 0;
  85. CV_WRAP virtual double getNoiseSigma() const = 0;
  86. CV_WRAP virtual void setNoiseSigma(double noiseSigma) = 0;
  87. };
  88. /** @brief Creates mixture-of-gaussian background subtractor
  89. @param history Length of the history.
  90. @param nmixtures Number of Gaussian mixtures.
  91. @param backgroundRatio Background ratio.
  92. @param noiseSigma Noise strength (standard deviation of the brightness or each color channel). 0
  93. means some automatic value.
  94. */
  95. CV_EXPORTS_W Ptr<cuda::BackgroundSubtractorMOG>
  96. createBackgroundSubtractorMOG(int history = 200, int nmixtures = 5,
  97. double backgroundRatio = 0.7, double noiseSigma = 0);
  98. ////////////////////////////////////////////////////
  99. // MOG2
  100. /** @brief Gaussian Mixture-based Background/Foreground Segmentation Algorithm.
  101. The class discriminates between foreground and background pixels by building and maintaining a model
  102. of the background. Any pixel which does not fit this model is then deemed to be foreground. The
  103. class implements algorithm described in @cite Zivkovic2004 .
  104. @sa BackgroundSubtractorMOG2
  105. */
  106. class CV_EXPORTS_W BackgroundSubtractorMOG2 : public cv::BackgroundSubtractorMOG2
  107. {
  108. public:
  109. using cv::BackgroundSubtractorMOG2::apply;
  110. using cv::BackgroundSubtractorMOG2::getBackgroundImage;
  111. CV_WRAP virtual void apply(InputArray image, OutputArray fgmask, double learningRate, Stream& stream) = 0;
  112. virtual void getBackgroundImage(OutputArray backgroundImage, Stream& stream) const = 0;
  113. CV_WRAP inline void getBackgroundImage(CV_OUT GpuMat &backgroundImage, Stream& stream) {
  114. getBackgroundImage(OutputArray(backgroundImage), stream);
  115. }
  116. };
  117. /** @brief Creates MOG2 Background Subtractor
  118. @param history Length of the history.
  119. @param varThreshold Threshold on the squared Mahalanobis distance between the pixel and the model
  120. to decide whether a pixel is well described by the background model. This parameter does not
  121. affect the background update.
  122. @param detectShadows If true, the algorithm will detect shadows and mark them. It decreases the
  123. speed a bit, so if you do not need this feature, set the parameter to false.
  124. */
  125. CV_EXPORTS_W Ptr<cuda::BackgroundSubtractorMOG2>
  126. createBackgroundSubtractorMOG2(int history = 500, double varThreshold = 16,
  127. bool detectShadows = true);
  128. //! @}
  129. }} // namespace cv { namespace cuda {
  130. #endif /* OPENCV_CUDABGSEGM_HPP */