VAT  3.0
Video Analysis Tool
BackgroundSubtractorLBSP.h
1 #pragma once
2 
3 #include <opencv2/features2d/features2d.hpp>
4 #include <opencv2/video/background_segm.hpp>
5 #include "custom_utils/LBSP.h"
6 #include "custom_utils/DistanceUtils.h"
7 #include "custom_utils/RandUtils.h"
8 #include <iostream>
9 #include <opencv2/imgproc/imgproc.hpp>
10 #include <opencv2/highgui/highgui.hpp>
11 #include <iomanip>
12 #include <exception>
13 
23 class BackgroundSubtractorLBSP : public cv::BackgroundSubtractor {
24 public:
26  BackgroundSubtractorLBSP(float fRelLBSPThreshold, size_t nLBSPThresholdOffset=0);
28  virtual ~BackgroundSubtractorLBSP();
30  virtual void initialize(const cv::Mat& oInitImg);
32  virtual void initialize(const cv::Mat& oInitImg, const cv::Mat& oROI)=0;
34  virtual void apply(cv::InputArray image, cv::OutputArray fgmask, double learningRate=0)=0;
36  virtual cv::Mat getROICopy() const;
38  virtual void setROI(cv::Mat& oROI);
40  void setAutomaticModelReset(bool);
41 
42 protected:
43  struct PxInfoBase {
44  int nImgCoord_Y;
45  int nImgCoord_X;
46  size_t nModelIdx;
47  };
49  cv::Mat m_oROI;
51  cv::Size m_oImgSize;
57  const size_t m_nLBSPThresholdOffset;
59  const float m_fRelLBSPThreshold;
61  size_t m_nTotPxCount, m_nTotRelevantPxCount;
63  size_t m_nFrameIndex, m_nFramesSinceLastReset, m_nModelResetCooldown;
65  size_t m_anLBSPThreshold_8bitLUT[UCHAR_MAX+1];
67  size_t* m_aPxIdxLUT;
83  cv::Mat m_oLastFGMask;
84 
85 private:
90 
91 public:
92  // ######## DEBUG PURPOSES ONLY ##########
93  int m_nDebugCoordX, m_nDebugCoordY;
94  std::string m_sDebugName;
95  cv::FileStorage* m_pDebugFS;
96 };
size_t m_nImgChannels
input image channel size
Definition: BackgroundSubtractorLBSP.h:53
size_t * m_aPxIdxLUT
internal pixel index LUT for all relevant analysis regions (based on the provided ROI) ...
Definition: BackgroundSubtractorLBSP.h:67
Definition: BackgroundSubtractorLBSP.h:23
cv::Mat m_oLastDescFrame
copy of latest descriptors (used when refreshing model)
Definition: BackgroundSubtractorLBSP.h:81
bool m_bInitialized
specifies whether the algorithm is fully initialized or not
Definition: BackgroundSubtractorLBSP.h:73
const size_t m_nLBSPThresholdOffset
LBSP internal threshold offset value, used to reduce texture noise in dark regions.
Definition: BackgroundSubtractorLBSP.h:57
void setAutomaticModelReset(bool)
turns automatic model reset on or off
Definition: BackgroundSubtractorLBSP.cpp:50
cv::Size m_oImgSize
input image size
Definition: BackgroundSubtractorLBSP.h:51
bool m_bUsingMovingCamera
specifies whether the camera is considered moving or not
Definition: BackgroundSubtractorLBSP.h:77
Definition: BackgroundSubtractorLBSP.h:43
int m_nImgType
input image type
Definition: BackgroundSubtractorLBSP.h:55
virtual void apply(cv::InputArray image, cv::OutputArray fgmask, double learningRate=0)=0
primary model update function; the learning param is used to override the internal learning speed (ig...
size_t m_nFrameIndex
current frame index, frame count since last model reset & model reset cooldown counters ...
Definition: BackgroundSubtractorLBSP.h:63
virtual void initialize(const cv::Mat &oInitImg)
(re)initiaization method; needs to be called before starting background subtraction ...
Definition: BackgroundSubtractorLBSP.cpp:30
size_t m_anLBSPThreshold_8bitLUT[UCHAR_MAX+1]
pre-allocated internal LBSP threshold values LUT for all possible 8-bit intensities ...
Definition: BackgroundSubtractorLBSP.h:65
BackgroundSubtractorLBSP(float fRelLBSPThreshold, size_t nLBSPThresholdOffset=0)
full constructor
Definition: BackgroundSubtractorLBSP.cpp:6
PxInfoBase * m_aPxInfoLUT
internal pixel info LUT for all possible pixel indexes
Definition: BackgroundSubtractorLBSP.h:69
cv::Mat m_oROI
background model ROI used for LBSP descriptor extraction (specific to the input image size) ...
Definition: BackgroundSubtractorLBSP.h:49
const int m_nDefaultMedianBlurKernelSize
default kernel size for median blur post-proc filtering
Definition: BackgroundSubtractorLBSP.h:71
const float m_fRelLBSPThreshold
LBSP relative internal threshold (kept here since we don&#39;t keep an LBSP object)
Definition: BackgroundSubtractorLBSP.h:59
cv::Mat m_oLastColorFrame
copy of latest pixel intensities (used when refreshing model)
Definition: BackgroundSubtractorLBSP.h:79
bool m_bAutoModelResetEnabled
specifies whether automatic model resets are enabled or not
Definition: BackgroundSubtractorLBSP.h:75
virtual cv::Mat getROICopy() const
returns a copy of the ROI used for descriptor extraction
Definition: BackgroundSubtractorLBSP.cpp:34
virtual void setROI(cv::Mat &oROI)
sets the ROI to be used for descriptor extraction (note: this function will reinit the model and retu...
Definition: BackgroundSubtractorLBSP.cpp:38
cv::Mat m_oLastFGMask
the foreground mask generated by the method at [t-1]
Definition: BackgroundSubtractorLBSP.h:83
virtual ~BackgroundSubtractorLBSP()
default destructor
Definition: BackgroundSubtractorLBSP.cpp:28
size_t m_nTotPxCount
total number of pixels (depends on the input frame size) & total number of relevant pixels ...
Definition: BackgroundSubtractorLBSP.h:61