github.com/kaydxh/golang@v0.0.131/pkg/gocv/cgo/third_path/opencv4/include/opencv2/video/background_segm.hpp (about)

     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  // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
    16  // Third party copyrights are property of their respective owners.
    17  //
    18  // Redistribution and use in source and binary forms, with or without modification,
    19  // are permitted provided that the following conditions are met:
    20  //
    21  //   * Redistribution's of source code must retain the above copyright notice,
    22  //     this list of conditions and the following disclaimer.
    23  //
    24  //   * Redistribution's in binary form must reproduce the above copyright notice,
    25  //     this list of conditions and the following disclaimer in the documentation
    26  //     and/or other materials provided with the distribution.
    27  //
    28  //   * The name of the copyright holders may not be used to endorse or promote products
    29  //     derived from this software without specific prior written permission.
    30  //
    31  // This software is provided by the copyright holders and contributors "as is" and
    32  // any express or implied warranties, including, but not limited to, the implied
    33  // warranties of merchantability and fitness for a particular purpose are disclaimed.
    34  // In no event shall the Intel Corporation or contributors be liable for any direct,
    35  // indirect, incidental, special, exemplary, or consequential damages
    36  // (including, but not limited to, procurement of substitute goods or services;
    37  // loss of use, data, or profits; or business interruption) however caused
    38  // and on any theory of liability, whether in contract, strict liability,
    39  // or tort (including negligence or otherwise) arising in any way out of
    40  // the use of this software, even if advised of the possibility of such damage.
    41  //
    42  //M*/
    43  
    44  #ifndef OPENCV_BACKGROUND_SEGM_HPP
    45  #define OPENCV_BACKGROUND_SEGM_HPP
    46  
    47  #include "opencv2/core.hpp"
    48  
    49  namespace cv
    50  {
    51  
    52  //! @addtogroup video_motion
    53  //! @{
    54  
    55  /** @brief Base class for background/foreground segmentation. :
    56  
    57  The class is only used to define the common interface for the whole family of background/foreground
    58  segmentation algorithms.
    59   */
    60  class CV_EXPORTS_W BackgroundSubtractor : public Algorithm
    61  {
    62  public:
    63      /** @brief Computes a foreground mask.
    64  
    65      @param image Next video frame.
    66      @param fgmask The output foreground mask as an 8-bit binary image.
    67      @param learningRate The value between 0 and 1 that indicates how fast the background model is
    68      learnt. Negative parameter value makes the algorithm to use some automatically chosen learning
    69      rate. 0 means that the background model is not updated at all, 1 means that the background model
    70      is completely reinitialized from the last frame.
    71       */
    72      CV_WRAP virtual void apply(InputArray image, OutputArray fgmask, double learningRate=-1) = 0;
    73  
    74      /** @brief Computes a background image.
    75  
    76      @param backgroundImage The output background image.
    77  
    78      @note Sometimes the background image can be very blurry, as it contain the average background
    79      statistics.
    80       */
    81      CV_WRAP virtual void getBackgroundImage(OutputArray backgroundImage) const = 0;
    82  };
    83  
    84  
    85  /** @brief Gaussian Mixture-based Background/Foreground Segmentation Algorithm.
    86  
    87  The class implements the Gaussian mixture model background subtraction described in @cite Zivkovic2004
    88  and @cite Zivkovic2006 .
    89   */
    90  class CV_EXPORTS_W BackgroundSubtractorMOG2 : public BackgroundSubtractor
    91  {
    92  public:
    93      /** @brief Returns the number of last frames that affect the background model
    94      */
    95      CV_WRAP virtual int getHistory() const = 0;
    96      /** @brief Sets the number of last frames that affect the background model
    97      */
    98      CV_WRAP virtual void setHistory(int history) = 0;
    99  
   100      /** @brief Returns the number of gaussian components in the background model
   101      */
   102      CV_WRAP virtual int getNMixtures() const = 0;
   103      /** @brief Sets the number of gaussian components in the background model.
   104  
   105      The model needs to be reinitalized to reserve memory.
   106      */
   107      CV_WRAP virtual void setNMixtures(int nmixtures) = 0;//needs reinitialization!
   108  
   109      /** @brief Returns the "background ratio" parameter of the algorithm
   110  
   111      If a foreground pixel keeps semi-constant value for about backgroundRatio\*history frames, it's
   112      considered background and added to the model as a center of a new component. It corresponds to TB
   113      parameter in the paper.
   114       */
   115      CV_WRAP virtual double getBackgroundRatio() const = 0;
   116      /** @brief Sets the "background ratio" parameter of the algorithm
   117      */
   118      CV_WRAP virtual void setBackgroundRatio(double ratio) = 0;
   119  
   120      /** @brief Returns the variance threshold for the pixel-model match
   121  
   122      The main threshold on the squared Mahalanobis distance to decide if the sample is well described by
   123      the background model or not. Related to Cthr from the paper.
   124       */
   125      CV_WRAP virtual double getVarThreshold() const = 0;
   126      /** @brief Sets the variance threshold for the pixel-model match
   127      */
   128      CV_WRAP virtual void setVarThreshold(double varThreshold) = 0;
   129  
   130      /** @brief Returns the variance threshold for the pixel-model match used for new mixture component generation
   131  
   132      Threshold for the squared Mahalanobis distance that helps decide when a sample is close to the
   133      existing components (corresponds to Tg in the paper). If a pixel is not close to any component, it
   134      is considered foreground or added as a new component. 3 sigma =\> Tg=3\*3=9 is default. A smaller Tg
   135      value generates more components. A higher Tg value may result in a small number of components but
   136      they can grow too large.
   137       */
   138      CV_WRAP virtual double getVarThresholdGen() const = 0;
   139      /** @brief Sets the variance threshold for the pixel-model match used for new mixture component generation
   140      */
   141      CV_WRAP virtual void setVarThresholdGen(double varThresholdGen) = 0;
   142  
   143      /** @brief Returns the initial variance of each gaussian component
   144      */
   145      CV_WRAP virtual double getVarInit() const = 0;
   146      /** @brief Sets the initial variance of each gaussian component
   147      */
   148      CV_WRAP virtual void setVarInit(double varInit) = 0;
   149  
   150      CV_WRAP virtual double getVarMin() const = 0;
   151      CV_WRAP virtual void setVarMin(double varMin) = 0;
   152  
   153      CV_WRAP virtual double getVarMax() const = 0;
   154      CV_WRAP virtual void setVarMax(double varMax) = 0;
   155  
   156      /** @brief Returns the complexity reduction threshold
   157  
   158      This parameter defines the number of samples needed to accept to prove the component exists. CT=0.05
   159      is a default value for all the samples. By setting CT=0 you get an algorithm very similar to the
   160      standard Stauffer&Grimson algorithm.
   161       */
   162      CV_WRAP virtual double getComplexityReductionThreshold() const = 0;
   163      /** @brief Sets the complexity reduction threshold
   164      */
   165      CV_WRAP virtual void setComplexityReductionThreshold(double ct) = 0;
   166  
   167      /** @brief Returns the shadow detection flag
   168  
   169      If true, the algorithm detects shadows and marks them. See createBackgroundSubtractorMOG2 for
   170      details.
   171       */
   172      CV_WRAP virtual bool getDetectShadows() const = 0;
   173      /** @brief Enables or disables shadow detection
   174      */
   175      CV_WRAP virtual void setDetectShadows(bool detectShadows) = 0;
   176  
   177      /** @brief Returns the shadow value
   178  
   179      Shadow value is the value used to mark shadows in the foreground mask. Default value is 127. Value 0
   180      in the mask always means background, 255 means foreground.
   181       */
   182      CV_WRAP virtual int getShadowValue() const = 0;
   183      /** @brief Sets the shadow value
   184      */
   185      CV_WRAP virtual void setShadowValue(int value) = 0;
   186  
   187      /** @brief Returns the shadow threshold
   188  
   189      A shadow is detected if pixel is a darker version of the background. The shadow threshold (Tau in
   190      the paper) is a threshold defining how much darker the shadow can be. Tau= 0.5 means that if a pixel
   191      is more than twice darker then it is not shadow. See Prati, Mikic, Trivedi and Cucchiara,
   192      *Detecting Moving Shadows...*, IEEE PAMI,2003.
   193       */
   194      CV_WRAP virtual double getShadowThreshold() const = 0;
   195      /** @brief Sets the shadow threshold
   196      */
   197      CV_WRAP virtual void setShadowThreshold(double threshold) = 0;
   198  
   199      /** @brief Computes a foreground mask.
   200  
   201      @param image Next video frame. Floating point frame will be used without scaling and should be in range \f$[0,255]\f$.
   202      @param fgmask The output foreground mask as an 8-bit binary image.
   203      @param learningRate The value between 0 and 1 that indicates how fast the background model is
   204      learnt. Negative parameter value makes the algorithm to use some automatically chosen learning
   205      rate. 0 means that the background model is not updated at all, 1 means that the background model
   206      is completely reinitialized from the last frame.
   207       */
   208      CV_WRAP virtual void apply(InputArray image, OutputArray fgmask, double learningRate=-1) CV_OVERRIDE = 0;
   209  };
   210  
   211  /** @brief Creates MOG2 Background Subtractor
   212  
   213  @param history Length of the history.
   214  @param varThreshold Threshold on the squared Mahalanobis distance between the pixel and the model
   215  to decide whether a pixel is well described by the background model. This parameter does not
   216  affect the background update.
   217  @param detectShadows If true, the algorithm will detect shadows and mark them. It decreases the
   218  speed a bit, so if you do not need this feature, set the parameter to false.
   219   */
   220  CV_EXPORTS_W Ptr<BackgroundSubtractorMOG2>
   221      createBackgroundSubtractorMOG2(int history=500, double varThreshold=16,
   222                                     bool detectShadows=true);
   223  
   224  /** @brief K-nearest neighbours - based Background/Foreground Segmentation Algorithm.
   225  
   226  The class implements the K-nearest neighbours background subtraction described in @cite Zivkovic2006 .
   227  Very efficient if number of foreground pixels is low.
   228   */
   229  class CV_EXPORTS_W BackgroundSubtractorKNN : public BackgroundSubtractor
   230  {
   231  public:
   232      /** @brief Returns the number of last frames that affect the background model
   233      */
   234      CV_WRAP virtual int getHistory() const = 0;
   235      /** @brief Sets the number of last frames that affect the background model
   236      */
   237      CV_WRAP virtual void setHistory(int history) = 0;
   238  
   239      /** @brief Returns the number of data samples in the background model
   240      */
   241      CV_WRAP virtual int getNSamples() const = 0;
   242      /** @brief Sets the number of data samples in the background model.
   243  
   244      The model needs to be reinitalized to reserve memory.
   245      */
   246      CV_WRAP virtual void setNSamples(int _nN) = 0;//needs reinitialization!
   247  
   248      /** @brief Returns the threshold on the squared distance between the pixel and the sample
   249  
   250      The threshold on the squared distance between the pixel and the sample to decide whether a pixel is
   251      close to a data sample.
   252       */
   253      CV_WRAP virtual double getDist2Threshold() const = 0;
   254      /** @brief Sets the threshold on the squared distance
   255      */
   256      CV_WRAP virtual void setDist2Threshold(double _dist2Threshold) = 0;
   257  
   258      /** @brief Returns the number of neighbours, the k in the kNN.
   259  
   260      K is the number of samples that need to be within dist2Threshold in order to decide that that
   261      pixel is matching the kNN background model.
   262       */
   263      CV_WRAP virtual int getkNNSamples() const = 0;
   264      /** @brief Sets the k in the kNN. How many nearest neighbours need to match.
   265      */
   266      CV_WRAP virtual void setkNNSamples(int _nkNN) = 0;
   267  
   268      /** @brief Returns the shadow detection flag
   269  
   270      If true, the algorithm detects shadows and marks them. See createBackgroundSubtractorKNN for
   271      details.
   272       */
   273      CV_WRAP virtual bool getDetectShadows() const = 0;
   274      /** @brief Enables or disables shadow detection
   275      */
   276      CV_WRAP virtual void setDetectShadows(bool detectShadows) = 0;
   277  
   278      /** @brief Returns the shadow value
   279  
   280      Shadow value is the value used to mark shadows in the foreground mask. Default value is 127. Value 0
   281      in the mask always means background, 255 means foreground.
   282       */
   283      CV_WRAP virtual int getShadowValue() const = 0;
   284      /** @brief Sets the shadow value
   285      */
   286      CV_WRAP virtual void setShadowValue(int value) = 0;
   287  
   288      /** @brief Returns the shadow threshold
   289  
   290      A shadow is detected if pixel is a darker version of the background. The shadow threshold (Tau in
   291      the paper) is a threshold defining how much darker the shadow can be. Tau= 0.5 means that if a pixel
   292      is more than twice darker then it is not shadow. See Prati, Mikic, Trivedi and Cucchiara,
   293      *Detecting Moving Shadows...*, IEEE PAMI,2003.
   294       */
   295      CV_WRAP virtual double getShadowThreshold() const = 0;
   296      /** @brief Sets the shadow threshold
   297       */
   298      CV_WRAP virtual void setShadowThreshold(double threshold) = 0;
   299  };
   300  
   301  /** @brief Creates KNN Background Subtractor
   302  
   303  @param history Length of the history.
   304  @param dist2Threshold Threshold on the squared distance between the pixel and the sample to decide
   305  whether a pixel is close to that sample. This parameter does not affect the background update.
   306  @param detectShadows If true, the algorithm will detect shadows and mark them. It decreases the
   307  speed a bit, so if you do not need this feature, set the parameter to false.
   308   */
   309  CV_EXPORTS_W Ptr<BackgroundSubtractorKNN>
   310      createBackgroundSubtractorKNN(int history=500, double dist2Threshold=400.0,
   311                                     bool detectShadows=true);
   312  
   313  //! @} video_motion
   314  
   315  } // cv
   316  
   317  #endif