VAT  3.0
Video Analysis Tool
BackgroundSubtractorPAWCS.h
1 #pragma once
2 
3 #include "BackgroundSubtractorLBSP.h"
4 #include "custom_utils/DistanceUtils.h"
5 #include "custom_utils/RandUtils.h"
6 #include <iostream>
7 #include <opencv2/imgproc/imgproc.hpp>
8 #include <opencv2/highgui/highgui.hpp>
9 #include <iomanip>
10 #include "ThermalColor.h"
11 #include "ReliabilityBg.h"
12 
14 #define BGSPAWCS_DEFAULT_LBSP_REL_SIMILARITY_THRESHOLD (0.333f)
15 #define BGSPAWCS_DEFAULT_DESC_DIST_THRESHOLD_OFFSET (2)
17 #define BGSPAWCS_DEFAULT_MIN_COLOR_DIST_THRESHOLD (20)
19 #define BGSPAWCS_DEFAULT_MAX_NB_WORDS (50)
21 #define BGSPAWCS_DEFAULT_N_SAMPLES_FOR_MV_AVGS (100)
23 
36 public:
38  BackgroundSubtractorPAWCS( float fRelLBSPThreshold=BGSPAWCS_DEFAULT_LBSP_REL_SIMILARITY_THRESHOLD,
39  size_t nDescDistThresholdOffset=BGSPAWCS_DEFAULT_DESC_DIST_THRESHOLD_OFFSET,
40  size_t nMinColorDistThreshold=BGSPAWCS_DEFAULT_MIN_COLOR_DIST_THRESHOLD,
41  size_t nMaxNbWords=BGSPAWCS_DEFAULT_MAX_NB_WORDS,
42  size_t nSamplesForMovingAvgs=BGSPAWCS_DEFAULT_N_SAMPLES_FOR_MV_AVGS);
46  virtual void initialize(const cv::Mat& oInitImg, const cv::Mat& oROI);
48  virtual void refreshModel(size_t nBaseOccCount, float fOccDecrFrac, bool bForceFGUpdate=false);
50  virtual void apply(cv::InputArray image, cv::OutputArray fgmask, double learningRateOverride=0);
51  virtual void apply(cv::InputArray image, cv::OutputArray fgmask, cv::OutputArray _featureMap, cv::OutputArray _reliabilityMap,
52  cv::OutputArray _foregroundRaw, double learningRateOverride=0);
54  virtual void getBackgroundImage(cv::OutputArray backgroundImage) const;
56  virtual void getBackgroundDescriptorsImage(cv::OutputArray backgroundDescImage) const;
57 
58 protected:
59  template<size_t nChannels>
61  uchar anColor[nChannels];
62  ushort anDesc[nChannels];
63  };
64  struct LocalWordBase {
65  size_t nFirstOcc;
66  size_t nLastOcc;
67  size_t nOccurrences;
68  };
69  template<typename T>
71  T oFeature;
72  };
73  struct GlobalWordBase {
74  float fLatestWeight;
75  cv::Mat oSpatioOccMap;
76  uchar nDescBITS;
77  };
78  template<typename T>
80  T oFeature;
81  };
86  struct PxInfo_PAWCS : PxInfoBase {
87  size_t nGlobalWordMapLookupIdx;
88  GlobalWordBase** apGlobalDictSortLUT;
89  };
95  size_t m_nMaxLocalWords, m_nCurrLocalWords;
97  size_t m_nMaxGlobalWords, m_nCurrGlobalWords;
105  cv::Size m_oDownSampledFrameSize_MotionAnalysis, m_oDownSampledFrameSize_GlobalWordLookup;
112 
115  LocalWord_1ch* m_aLocalWordList_1ch, *m_pLocalWordListIter_1ch;
116  LocalWord_3ch* m_aLocalWordList_3ch, *m_pLocalWordListIter_3ch;
117  GlobalWordBase** m_apGlobalWordDict;
118  GlobalWord_1ch* m_aGlobalWordList_1ch, *m_pGlobalWordListIter_1ch;
119  GlobalWord_3ch* m_aGlobalWordList_3ch, *m_pGlobalWordListIter_3ch;
120  PxInfo_PAWCS* m_aPxInfoLUT_PAWCS;
121 
131  cv::Mat m_oMeanMinDistFrame_LT, m_oMeanMinDistFrame_ST;
133  cv::Mat m_oMeanDownSampledLastDistFrame_LT, m_oMeanDownSampledLastDistFrame_ST;
135  cv::Mat m_oMeanRawSegmResFrame_LT, m_oMeanRawSegmResFrame_ST;
137  cv::Mat m_oMeanFinalSegmResFrame_LT, m_oMeanFinalSegmResFrame_ST;
141  cv::Mat m_oBlinksFrame;
146 
149  cv::Mat m_oFGMask_FloodedHoles;
150  cv::Mat m_oLastFGMask_dilated;
151  cv::Mat m_oLastFGMask_dilated_inverted;
152  cv::Mat m_oCurrRawFGBlinkMask;
153  cv::Mat m_oLastRawFGBlinkMask;
154  cv::Mat m_oTempGlobalWordWeightDiffFactor;
155  cv::Mat m_oMorphExStructElement;
156 
158  cv::Mat featureMap;
159  cv::Mat reliabilityMap;
160  cv::Mat foregroundRaw;
161  cv::Mat reliabilityMap2;
162  cv::Mat featureMap3;
163  cv::Mat reliabilityMap3;
164 
165  ReliabilityBg reliabilityBg;
166  float feature1, reliability1, feature2a, reliability2a, feature2b, reliability2b, feature3, reliability3;
167  float minScale, maxScale, threshold, scaleFactor;
168 
170  void CleanupDictionaries();
172  static float GetLocalWordWeight(const LocalWordBase* w, size_t nCurrFrame, size_t nOffset);
174  static float GetGlobalWordWeight(const GlobalWordBase* w);
175 };
cv::Mat m_oDistThresholdFrame
per-pixel distance thresholds (equivalent to &#39;R(x)&#39; in PBAS, but used as a relative value to determin...
Definition: BackgroundSubtractorPAWCS.h:127
size_t m_nMaxGlobalWords
max/curr number of global words used to build the global background model (may vary based on img/chan...
Definition: BackgroundSubtractorPAWCS.h:97
cv::Mat m_oMeanDownSampledLastDistFrame_LT
per-pixel mean downsampled distances between consecutive frames (used to analyze camera movement and ...
Definition: BackgroundSubtractorPAWCS.h:133
BackgroundSubtractorPAWCS(float fRelLBSPThreshold=BGSPAWCS_DEFAULT_LBSP_REL_SIMILARITY_THRESHOLD, size_t nDescDistThresholdOffset=BGSPAWCS_DEFAULT_DESC_DIST_THRESHOLD_OFFSET, size_t nMinColorDistThreshold=BGSPAWCS_DEFAULT_MIN_COLOR_DIST_THRESHOLD, size_t nMaxNbWords=BGSPAWCS_DEFAULT_MAX_NB_WORDS, size_t nSamplesForMovingAvgs=BGSPAWCS_DEFAULT_N_SAMPLES_FOR_MV_AVGS)
full constructor
Definition: BackgroundSubtractorPAWCS.cpp:59
cv::Mat m_oMeanRawSegmResFrame_LT
per-pixel mean raw segmentation results (used to detect unstable segmentation regions) ...
Definition: BackgroundSubtractorPAWCS.h:135
LocalWordBase ** m_apLocalWordDict
word lists & dictionaries
Definition: BackgroundSubtractorPAWCS.h:114
cv::Mat m_oMeanMinDistFrame_LT
per-pixel mean minimal distances from the model (&#39;D_min(x)&#39; in PBAS, used to control variation magnit...
Definition: BackgroundSubtractorPAWCS.h:131
virtual ~BackgroundSubtractorPAWCS()
default destructor
Definition: BackgroundSubtractorPAWCS.cpp:90
Definition: BackgroundSubtractorLBSP.h:23
void CleanupDictionaries()
internal cleanup function for the dictionary structures
Definition: BackgroundSubtractorPAWCS.cpp:1362
const size_t m_nDescDistThresholdOffset
absolute descriptor distance threshold offset
Definition: BackgroundSubtractorPAWCS.h:93
cv::Mat m_oFGMask_PreFlood
pre-allocated CV_8UC1 matrices used to speed up morph ops
Definition: BackgroundSubtractorPAWCS.h:148
Definition: BackgroundSubtractorPAWCS.h:73
virtual void getBackgroundImage(cv::OutputArray backgroundImage) const
returns a copy of the latest reconstructed background image
Definition: BackgroundSubtractorPAWCS.cpp:1307
cv::Mat m_oIllumUpdtRegionMask
a lookup map used to keep track of regions where illumination recently changed
Definition: BackgroundSubtractorPAWCS.h:123
cv::Mat m_oUnstableRegionMask
a lookup map used to keep track of unstable regions (based on segm. noise & local dist...
Definition: BackgroundSubtractorPAWCS.h:139
Definition: BackgroundSubtractorPAWCS.h:86
size_t m_nMaxLocalWords
max/curr number of local words used to build background submodels (for a single pixel, similar to &#39;N&#39; in ViBe/PBAS, may vary based on img/channel size)
Definition: BackgroundSubtractorPAWCS.h:95
Definition: BackgroundSubtractorPAWCS.h:79
virtual void getBackgroundDescriptorsImage(cv::OutputArray backgroundDescImage) const
returns a copy of the latest reconstructed background descriptors image
Definition: BackgroundSubtractorPAWCS.cpp:1342
size_t m_nLocalWordWeightOffset
current local word weight offset
Definition: BackgroundSubtractorPAWCS.h:111
cv::Mat featureMap
Features and reliability Maps.
Definition: BackgroundSubtractorPAWCS.h:158
cv::Mat m_oDownSampledFrame_MotionAnalysis
pre-allocated matrix used to downsample the input frame when needed
Definition: BackgroundSubtractorPAWCS.h:143
Definition: BackgroundSubtractorPAWCS.h:60
int m_nMedianBlurKernelSize
current kernel size for median blur post-proc filtering
Definition: BackgroundSubtractorPAWCS.h:103
Definition: BackgroundSubtractorPAWCS.h:64
virtual void refreshModel(size_t nBaseOccCount, float fOccDecrFrac, bool bForceFGUpdate=false)
refreshes all local (+ global) dictionaries based on the last analyzed frame
Definition: BackgroundSubtractorPAWCS.cpp:283
Definition: BackgroundSubtractorPAWCS.h:35
virtual void apply(cv::InputArray image, cv::OutputArray fgmask, double learningRateOverride=0)
primary model update function; the learning param is used to override the internal learning speed (ig...
Definition: BackgroundSubtractorPAWCS.cpp:612
cv::Mat m_oMeanFinalSegmResFrame_LT
per-pixel mean raw segmentation results (used to detect unstable segmentation regions) ...
Definition: BackgroundSubtractorPAWCS.h:137
Definition: BackgroundSubtractorPAWCS.h:70
static float GetGlobalWordWeight(const GlobalWordBase *w)
internal weight lookup function for global words
Definition: BackgroundSubtractorPAWCS.cpp:1408
static float GetLocalWordWeight(const LocalWordBase *w, size_t nCurrFrame, size_t nOffset)
internal weight lookup function for local words
Definition: BackgroundSubtractorPAWCS.cpp:1404
cv::Mat m_oLastRawFGMask
the foreground mask generated by the method at [t-1] (without post-proc, used for blinking px detecti...
Definition: BackgroundSubtractorPAWCS.h:145
virtual void initialize(const cv::Mat &oInitImg, const cv::Mat &oROI)
(re)initiaization method; needs to be called before starting background subtraction ...
Definition: BackgroundSubtractorPAWCS.cpp:94
cv::Mat m_oUpdateRateFrame
per-pixel update rates (&#39;T(x)&#39; in PBAS, which contains pixel-level &#39;sigmas&#39;, as referred to in ViBe) ...
Definition: BackgroundSubtractorPAWCS.h:125
cv::Mat m_oDistThresholdVariationFrame
per-pixel distance threshold variation modulators (&#39;v(x)&#39;, relative value used to modulate &#39;R(x)&#39; and...
Definition: BackgroundSubtractorPAWCS.h:129
size_t m_nDownSampledROIPxCount
total pixel count for the downsampled ROIs
Definition: BackgroundSubtractorPAWCS.h:109
float m_fLastNonFlatRegionRatio
last calculated non-flat region ratio
Definition: BackgroundSubtractorPAWCS.h:101
const size_t m_nMinColorDistThreshold
absolute minimal color distance threshold (&#39;R&#39; or &#39;radius&#39; in the original ViBe paper, used as the default/initial &#39;R(x)&#39; value here)
Definition: BackgroundSubtractorPAWCS.h:91
cv::Mat m_oDownSampledROI_MotionAnalysis
downsampled version of the ROI used for cam motion analysis
Definition: BackgroundSubtractorPAWCS.h:107
cv::Mat m_oBlinksFrame
per-pixel blink detection map (&#39;Z(x)&#39;)
Definition: BackgroundSubtractorPAWCS.h:141
Definition: ReliabilityBg.h:8
cv::Size m_oDownSampledFrameSize_MotionAnalysis
specifies the downsampled frame size used for cam motion analysis & gword lookup maps ...
Definition: BackgroundSubtractorPAWCS.h:105
const size_t m_nSamplesForMovingAvgs
number of samples to use to compute the learning rate of moving averages
Definition: BackgroundSubtractorPAWCS.h:99