Commit 14b1e8c7 authored by unknown's avatar unknown

New KNN code -should compile now

parent afa62c41
......@@ -596,7 +596,7 @@ Returns the number of gaussian components in the background model
BackgroundSubtractorMOG2::setNMixtures
--------------------------------------
Sets the number of gaussian components in the background model
Sets the number of gaussian components in the background model. The model needs to be reinitalized to reserve memory.
.. ocv:function:: void BackgroundSubtractorMOG2::setNMixtures(int nmixtures)
......@@ -615,9 +615,23 @@ Sets the "background ratio" parameter of the algorithm
.. ocv:function:: void BackgroundSubtractorMOG2::setBackgroundRatio(double ratio)
BackgroundSubtractorMOG2::getVarThreshold
---------------------------------------------
Returns the variance threshold for the pixel-model match
.. ocv:function:: double BackgroundSubtractorMOG2::getVarThreshold() const
The main threshold on the squared Mahalanobis distance to decide if the sample is well described by the background model or not. Related to Cthr from the paper.
BackgroundSubtractorMOG2::setVarThreshold
---------------------------------------------
Sets the variance threshold for the pixel-model match
.. ocv:function:: void BackgroundSubtractorMOG2::setVarThreshold(double varThreshold)
BackgroundSubtractorMOG2::getVarThresholdGen
---------------------------------------------
Returns the variance scale factor for the pixel-model match
Returns the variance threshold for the pixel-model match used for new mixture component generation
.. ocv:function:: double BackgroundSubtractorMOG2::getVarThresholdGen() const
......@@ -625,7 +639,7 @@ Threshold for the squared Mahalanobis distance that helps decide when a sample i
BackgroundSubtractorMOG2::setVarThresholdGen
---------------------------------------------
Sets the variance scale factor for the pixel-model match
Sets the variance threshold for the pixel-model match used for new mixture component generation
.. ocv:function:: void BackgroundSubtractorMOG2::setVarThresholdGen(double varThresholdGen)
......@@ -700,6 +714,126 @@ Sets the shadow threshold
.. ocv:function:: void BackgroundSubtractorMOG2::setShadowThreshold(double threshold)
BackgroundSubtractorKNN
------------------------
K-nearest neigbours - based Background/Foreground Segmentation Algorithm.
.. ocv:class:: BackgroundSubtractorKNN : public BackgroundSubtractor
The class implements the K-nearest neigbours background subtraction described in [Zivkovic2006]_ . Very efficient if number of foreground pixels is low.
createBackgroundSubtractorKNN
--------------------------------------------------
Creates KNN Background Subtractor
.. ocv:function:: Ptr<BackgroundSubtractorKNN> createBackgroundSubtractorKNN( int history=500, double dist2Threshold=400.0, bool detectShadows=true )
:param history: Length of the history.
:param dist2Threshold: Threshold on the squared distance between the pixel and the sample to decide whether a pixel is close to that sample. This parameter does not affect the background update.
:param detectShadows: If true, the algorithm will detect shadows and mark them. It decreases the speed a bit, so if you do not need this feature, set the parameter to false.
BackgroundSubtractorKNN::getHistory
--------------------------------------
Returns the number of last frames that affect the background model
.. ocv:function:: int BackgroundSubtractorKNN::getHistory() const
BackgroundSubtractorKNN::setHistory
--------------------------------------
Sets the number of last frames that affect the background model
.. ocv:function:: void BackgroundSubtractorKNN::setHistory(int history)
BackgroundSubtractorKNN::getNSamples
--------------------------------------
Returns the number of data samples in the background model
.. ocv:function:: int BackgroundSubtractorKNN::getNSamples() const
BackgroundSubtractorKNN::setNSamples
--------------------------------------
Sets the number of data samples in the background model. The model needs to be reinitalized to reserve memory.
.. ocv:function:: void BackgroundSubtractorKNN::setNSamples(int nN)
BackgroundSubtractorKNN::getDist2Threshold
---------------------------------------------
Returns the threshold on the squared distance between the pixel and the sample
.. ocv:function:: double BackgroundSubtractorKNN::getDist2Threshold() const
The threshold on the squared distance between the pixel and the sample to decide whether a pixel is close to a data sample.
BackgroundSubtractorKNN::setDist2Threshold
---------------------------------------------
Sets the threshold on the squared distance
.. ocv:function:: void BackgroundSubtractorKNN::setDist2Threshold(double dist2Threshold)
BackgroundSubtractorKNN::getkNNSamples
---------------------------------------------
Returns the k in the kNN. K is the number of samples that need to be within dist2Threshold in order to decide that that pixel is matching the kNN background model.
.. ocv:function:: int BackgroundSubtractorKNN::getkNNSamples() const
BackgroundSubtractorKNN::setkNNSamples
---------------------------------------------
Sets the k in the kNN. How many nearest neigbours need to match.
.. ocv:function:: void BackgroundSubtractorKNN::setkNNSamples(int nKNN)
BackgroundSubtractorKNN::getDetectShadows
---------------------------------------------
Returns the shadow detection flag
.. ocv:function:: bool BackgroundSubtractorKNN::getDetectShadows() const
If true, the algorithm detects shadows and marks them. See createBackgroundSubtractorKNN for details.
BackgroundSubtractorKNN::setDetectShadows
---------------------------------------------
Enables or disables shadow detection
.. ocv:function:: void BackgroundSubtractorKNN::setDetectShadows(bool detectShadows)
BackgroundSubtractorKNN::getShadowValue
---------------------------------------------
Returns the shadow value
.. ocv:function:: int BackgroundSubtractorKNN::getShadowValue() const
Shadow value is the value used to mark shadows in the foreground mask. Default value is 127. Value 0 in the mask always means background, 255 means foreground.
BackgroundSubtractorKNN::setShadowValue
---------------------------------------------
Sets the shadow value
.. ocv:function:: void BackgroundSubtractorKNN::setShadowValue(int value)
BackgroundSubtractorKNN::getShadowThreshold
---------------------------------------------
Returns the shadow threshold
.. ocv:function:: double BackgroundSubtractorKNN::getShadowThreshold() const
A shadow is detected if pixel is a darker version of the background. The shadow threshold (``Tau`` in the paper) is a threshold defining how much darker the shadow can be. ``Tau= 0.5`` means that if a pixel is more than twice darker then it is not shadow. See Prati, Mikic, Trivedi and Cucchiarra, *Detecting Moving Shadows...*, IEEE PAMI,2003.
BackgroundSubtractorKNN::setShadowThreshold
---------------------------------------------
Sets the shadow threshold
.. ocv:function:: void BackgroundSubtractorKNN::setShadowThreshold(double threshold)
BackgroundSubtractorGMG
------------------------
Background Subtractor module based on the algorithm given in [Gold2012]_.
......
......@@ -113,7 +113,7 @@ public:
CV_WRAP virtual void setHistory(int history) = 0;
CV_WRAP virtual int getNMixtures() const = 0;
CV_WRAP virtual void setNMixtures(int nmixtures) = 0;
CV_WRAP virtual void setNMixtures(int nmixtures) = 0;//needs reinitialization!
CV_WRAP virtual double getBackgroundRatio() const = 0;
CV_WRAP virtual void setBackgroundRatio(double ratio) = 0;
......@@ -150,6 +150,45 @@ CV_EXPORTS_W Ptr<BackgroundSubtractorMOG2>
createBackgroundSubtractorMOG2(int history=500, double varThreshold=16,
bool detectShadows=true);
/*!
The class implements the K nearest neigbours algorithm from:
"Efficient Adaptive Density Estimation per Image Pixel for the Task of Background Subtraction"
Z.Zivkovic, F. van der Heijden
Pattern Recognition Letters, vol. 27, no. 7, pages 773-780, 2006
http://www.zoranz.net/Publications/zivkovicPRL2006.pdf
Fast for small foreground object. Results on the benchmark data is at http://www.changedetection.net.
*/
class CV_EXPORTS_W BackgroundSubtractorKNN : public BackgroundSubtractor
{
public:
CV_WRAP virtual int getHistory() const = 0;
CV_WRAP virtual void setHistory(int history) = 0;
CV_WRAP virtual int getNSamples() const = 0;
CV_WRAP virtual void setNSamples(int _nN) = 0;//needs reinitialization!
CV_WRAP virtual double getDist2Threshold() const = 0;
CV_WRAP virtual void setDist2Threshold(double _dist2Threshold) = 0;
CV_WRAP virtual int getkNNSamples() const = 0;
CV_WRAP virtual void setkNNSamples(int _nkNN) = 0;
CV_WRAP virtual bool getDetectShadows() const = 0;
CV_WRAP virtual void setDetectShadows(bool detectShadows) = 0;
CV_WRAP virtual int getShadowValue() const = 0;
CV_WRAP virtual void setShadowValue(int value) = 0;
CV_WRAP virtual double getShadowThreshold() const = 0;
CV_WRAP virtual void setShadowThreshold(double threshold) = 0;
};
CV_EXPORTS_W Ptr<BackgroundSubtractorKNN>
createBackgroundSubtractorKNN(int history=500, double dist2Threshold=400.0,
bool detectShadows=true);
/**
* Background Subtractor module. Takes a series of images and returns a sequence of mask (8UC1)
* images of the same size, where 255 indicates Foreground and 0 represents Background.
......
This diff is collapsed.
......@@ -52,7 +52,7 @@ int main(int argc, const char** argv)
namedWindow("foreground image", WINDOW_NORMAL);
namedWindow("mean background image", WINDOW_NORMAL);
Ptr<BackgroundSubtractor> bg_model = createBackgroundSubtractorMOG2();
Ptr<BackgroundSubtractor> bg_model = createBackgroundSubtractorKNN();
Mat img, fgmask, fgimg;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment