bgsegm.hpp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. By downloading, copying, installing or using the software you agree to this
  3. license. If you do not agree to this license, do not download, install,
  4. copy or use the software.
  5. License Agreement
  6. For Open Source Computer Vision Library
  7. (3-clause BSD License)
  8. Copyright (C) 2013, OpenCV Foundation, all rights reserved.
  9. Third party copyrights are property of their respective owners.
  10. Redistribution and use in source and binary forms, with or without modification,
  11. are permitted provided that the following conditions are met:
  12. * Redistributions of source code must retain the above copyright notice,
  13. this list of conditions and the following disclaimer.
  14. * Redistributions in binary form must reproduce the above copyright notice,
  15. this list of conditions and the following disclaimer in the documentation
  16. and/or other materials provided with the distribution.
  17. * Neither the names of the copyright holders nor the names of the contributors
  18. may be used to endorse or promote products derived from this software
  19. without specific prior written permission.
  20. This software is provided by the copyright holders and contributors "as is" and
  21. any express or implied warranties, including, but not limited to, the implied
  22. warranties of merchantability and fitness for a particular purpose are
  23. disclaimed. In no event shall copyright holders or contributors be liable for
  24. any direct, indirect, incidental, special, exemplary, or consequential damages
  25. (including, but not limited to, procurement of substitute goods or services;
  26. loss of use, data, or profits; or business interruption) however caused
  27. and on any theory of liability, whether in contract, strict liability,
  28. or tort (including negligence or otherwise) arising in any way out of
  29. the use of this software, even if advised of the possibility of such damage.
  30. */
  31. #ifndef __OPENCV_BGSEGM_HPP__
  32. #define __OPENCV_BGSEGM_HPP__
  33. #include "opencv2/video.hpp"
  34. #ifdef __cplusplus
  35. /** @defgroup bgsegm Improved Background-Foreground Segmentation Methods
  36. */
  37. namespace cv
  38. {
  39. namespace bgsegm
  40. {
  41. //! @addtogroup bgsegm
  42. //! @{
  43. /** @brief Gaussian Mixture-based Background/Foreground Segmentation Algorithm.
  44. The class implements the algorithm described in @cite KB2001 .
  45. */
  46. class CV_EXPORTS_W BackgroundSubtractorMOG : public BackgroundSubtractor
  47. {
  48. public:
  49. CV_WRAP virtual int getHistory() const = 0;
  50. CV_WRAP virtual void setHistory(int nframes) = 0;
  51. CV_WRAP virtual int getNMixtures() const = 0;
  52. CV_WRAP virtual void setNMixtures(int nmix) = 0;
  53. CV_WRAP virtual double getBackgroundRatio() const = 0;
  54. CV_WRAP virtual void setBackgroundRatio(double backgroundRatio) = 0;
  55. CV_WRAP virtual double getNoiseSigma() const = 0;
  56. CV_WRAP virtual void setNoiseSigma(double noiseSigma) = 0;
  57. };
  58. /** @brief Creates mixture-of-gaussian background subtractor
  59. @param history Length of the history.
  60. @param nmixtures Number of Gaussian mixtures.
  61. @param backgroundRatio Background ratio.
  62. @param noiseSigma Noise strength (standard deviation of the brightness or each color channel). 0
  63. means some automatic value.
  64. */
  65. CV_EXPORTS_W Ptr<BackgroundSubtractorMOG>
  66. createBackgroundSubtractorMOG(int history=200, int nmixtures=5,
  67. double backgroundRatio=0.7, double noiseSigma=0);
  68. /** @brief Background Subtractor module based on the algorithm given in @cite Gold2012 .
  69. Takes a series of images and returns a sequence of mask (8UC1)
  70. images of the same size, where 255 indicates Foreground and 0 represents Background.
  71. This class implements an algorithm described in "Visual Tracking of Human Visitors under
  72. Variable-Lighting Conditions for a Responsive Audio Art Installation," A. Godbehere,
  73. A. Matsukawa, K. Goldberg, American Control Conference, Montreal, June 2012.
  74. */
  75. class CV_EXPORTS_W BackgroundSubtractorGMG : public BackgroundSubtractor
  76. {
  77. public:
  78. /** @brief Returns total number of distinct colors to maintain in histogram.
  79. */
  80. CV_WRAP virtual int getMaxFeatures() const = 0;
  81. /** @brief Sets total number of distinct colors to maintain in histogram.
  82. */
  83. CV_WRAP virtual void setMaxFeatures(int maxFeatures) = 0;
  84. /** @brief Returns the learning rate of the algorithm.
  85. It lies between 0.0 and 1.0. It determines how quickly features are "forgotten" from
  86. histograms.
  87. */
  88. CV_WRAP virtual double getDefaultLearningRate() const = 0;
  89. /** @brief Sets the learning rate of the algorithm.
  90. */
  91. CV_WRAP virtual void setDefaultLearningRate(double lr) = 0;
  92. /** @brief Returns the number of frames used to initialize background model.
  93. */
  94. CV_WRAP virtual int getNumFrames() const = 0;
  95. /** @brief Sets the number of frames used to initialize background model.
  96. */
  97. CV_WRAP virtual void setNumFrames(int nframes) = 0;
  98. /** @brief Returns the parameter used for quantization of color-space.
  99. It is the number of discrete levels in each channel to be used in histograms.
  100. */
  101. CV_WRAP virtual int getQuantizationLevels() const = 0;
  102. /** @brief Sets the parameter used for quantization of color-space
  103. */
  104. CV_WRAP virtual void setQuantizationLevels(int nlevels) = 0;
  105. /** @brief Returns the prior probability that each individual pixel is a background pixel.
  106. */
  107. CV_WRAP virtual double getBackgroundPrior() const = 0;
  108. /** @brief Sets the prior probability that each individual pixel is a background pixel.
  109. */
  110. CV_WRAP virtual void setBackgroundPrior(double bgprior) = 0;
  111. /** @brief Returns the kernel radius used for morphological operations
  112. */
  113. CV_WRAP virtual int getSmoothingRadius() const = 0;
  114. /** @brief Sets the kernel radius used for morphological operations
  115. */
  116. CV_WRAP virtual void setSmoothingRadius(int radius) = 0;
  117. /** @brief Returns the value of decision threshold.
  118. Decision value is the value above which pixel is determined to be FG.
  119. */
  120. CV_WRAP virtual double getDecisionThreshold() const = 0;
  121. /** @brief Sets the value of decision threshold.
  122. */
  123. CV_WRAP virtual void setDecisionThreshold(double thresh) = 0;
  124. /** @brief Returns the status of background model update
  125. */
  126. CV_WRAP virtual bool getUpdateBackgroundModel() const = 0;
  127. /** @brief Sets the status of background model update
  128. */
  129. CV_WRAP virtual void setUpdateBackgroundModel(bool update) = 0;
  130. /** @brief Returns the minimum value taken on by pixels in image sequence. Usually 0.
  131. */
  132. CV_WRAP virtual double getMinVal() const = 0;
  133. /** @brief Sets the minimum value taken on by pixels in image sequence.
  134. */
  135. CV_WRAP virtual void setMinVal(double val) = 0;
  136. /** @brief Returns the maximum value taken on by pixels in image sequence. e.g. 1.0 or 255.
  137. */
  138. CV_WRAP virtual double getMaxVal() const = 0;
  139. /** @brief Sets the maximum value taken on by pixels in image sequence.
  140. */
  141. CV_WRAP virtual void setMaxVal(double val) = 0;
  142. };
  143. /** @brief Creates a GMG Background Subtractor
  144. @param initializationFrames number of frames used to initialize the background models.
  145. @param decisionThreshold Threshold value, above which it is marked foreground, else background.
  146. */
  147. CV_EXPORTS_W Ptr<BackgroundSubtractorGMG> createBackgroundSubtractorGMG(int initializationFrames=120,
  148. double decisionThreshold=0.8);
  149. //! @}
  150. }
  151. }
  152. #endif
  153. #endif