├── BackgroundSubtractorLBSP.cpp ├── BackgroundSubtractorLBSP.h ├── BackgroundSubtractorSuBSENSE.cpp ├── BackgroundSubtractorSuBSENSE.h ├── DistanceUtils.h ├── LBSP.cpp ├── LBSP.h ├── LBSP_16bits_dbcross_1ch.i ├── LBSP_16bits_dbcross_3ch1t.i ├── LBSP_16bits_dbcross_3ch3t.i ├── LBSP_16bits_dbcross_s3ch.i ├── README.md ├── RandUtils.h ├── ViBe_LBSP.sdf ├── ViBe_LBSP.sln ├── ViBe_LBSP ├── Debug │ ├── BackgroundSubtractorLBSP.obj │ ├── BackgroundSubtractorSuBSENSE.obj │ ├── CL.read.1.tlog │ ├── CL.write.1.tlog │ ├── LBSP.obj │ ├── ViBe_LBSP.Build.CppClean.log │ ├── ViBe_LBSP.exe.intermediate.manifest │ ├── ViBe_LBSP.lastbuildstate │ ├── ViBe_LBSP.log │ ├── ViBe_LBSP.vcxprojResolveAssemblyReference.cache │ ├── bgfg_segm.obj │ ├── cl.command.1.tlog │ ├── link.command.1.tlog │ ├── link.read.1.tlog │ ├── link.write.1.tlog │ ├── mt.command.1.tlog │ ├── mt.read.1.tlog │ ├── mt.read.2.tlog │ ├── mt.write.1.tlog │ ├── vc100.idb │ └── vc100.pdb ├── ViBe_LBSP.vcxproj ├── ViBe_LBSP.vcxproj.filters ├── ViBe_LBSP.vcxproj.user ├── readfolder.cpp ├── readfolder.h ├── test_SuBSENSE.cpp └── x64 │ └── Debug │ ├── BackgroundSubtractorLBSP.obj │ ├── BackgroundSubtractorSuBSENSE.obj │ ├── CL.read.1.tlog │ ├── CL.write.1.tlog │ ├── LBSP.obj │ ├── ViBe_LBSP.exe.intermediate.manifest │ ├── ViBe_LBSP.lastbuildstate │ ├── ViBe_LBSP.log │ ├── ViBe_LBSP.vcxprojResolveAssemblyReference.cache │ ├── bgfg_segm.obj │ ├── cl.command.1.tlog │ ├── link.command.1.tlog │ ├── link.read.1.tlog │ ├── link.write.1.tlog │ ├── mt.command.1.tlog │ ├── mt.read.1.tlog │ ├── mt.read.2.tlog │ ├── mt.write.1.tlog │ ├── vc100.idb │ └── vc100.pdb ├── bgfg_segm.cpp ├── ipch └── vibe_lbsp-b01e80ba │ └── vibe_lbsp-6c103fc0.ipch ├── readfolder.cpp ├── readfolder.h └── x64 └── Debug ├── ViBe_LBSP.exe ├── ViBe_LBSP.ilk └── ViBe_LBSP.pdb /BackgroundSubtractorLBSP.cpp: -------------------------------------------------------------------------------- 1 | #include "BackgroundSubtractorLBSP.h" 2 | #include "DistanceUtils.h" 3 | #include "RandUtils.h" 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | // local define used to determine the default median blur kernel size 11 | #define DEFAULT_MEDIAN_BLUR_KERNEL_SIZE (9) 12 | 13 | BackgroundSubtractorLBSP::BackgroundSubtractorLBSP(float fRelLBSPThreshold, size_t nLBSPThresholdOffset) 14 | : m_nImgChannels(0) 15 | ,m_nImgType(0) 16 | ,m_nLBSPThresholdOffset(nLBSPThresholdOffset) 17 | ,m_fRelLBSPThreshold(fRelLBSPThreshold) 18 | ,m_nTotPxCount(0) 19 | ,m_nTotRelevantPxCount(0) 20 | ,m_nFrameIndex(SIZE_MAX) 21 | ,m_nFramesSinceLastReset(0) 22 | ,m_nModelResetCooldown(0) 23 | ,m_aPxIdxLUT(nullptr) 24 | ,m_aPxInfoLUT(nullptr) 25 | ,m_nDefaultMedianBlurKernelSize(DEFAULT_MEDIAN_BLUR_KERNEL_SIZE) 26 | ,m_bInitialized(false) 27 | ,m_bAutoModelResetEnabled(true) 28 | ,m_bUsingMovingCamera(false) 29 | ,nDebugCoordX(0),nDebugCoordY(0) { 30 | CV_Assert(m_fRelLBSPThreshold>=0); 31 | } 32 | 33 | BackgroundSubtractorLBSP::~BackgroundSubtractorLBSP() {} 34 | 35 | void BackgroundSubtractorLBSP::initialize(const cv::Mat& oInitImg) { 36 | this->initialize(oInitImg,cv::Mat()); 37 | } 38 | 39 | cv::AlgorithmInfo* BackgroundSubtractorLBSP::info() const { 40 | return nullptr; 41 | } 42 | 43 | cv::Mat BackgroundSubtractorLBSP::getROICopy() const { 44 | return m_oROI.clone(); 45 | } 46 | 47 | void BackgroundSubtractorLBSP::setROI(cv::Mat& oROI) { 48 | LBSP::validateROI(oROI); 49 | CV_Assert(cv::countNonZero(oROI)>0); 50 | if(m_bInitialized) { 51 | cv::Mat oLatestBackgroundImage; 52 | getBackgroundImage(oLatestBackgroundImage); 53 | initialize(oLatestBackgroundImage,oROI); 54 | } 55 | else 56 | m_oROI = oROI.clone(); 57 | } 58 | 59 | void BackgroundSubtractorLBSP::setAutomaticModelReset(bool bVal) { 60 | m_bAutoModelResetEnabled = bVal; 61 | } 62 | -------------------------------------------------------------------------------- /BackgroundSubtractorLBSP.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "LBSP.h" 6 | 7 | /*! 8 | Local Binary Similarity Pattern (LBSP)-based change detection algorithm (abstract version/base class). 9 | 10 | For more details on the different parameters, see P.-L. St-Charles and G.-A. Bilodeau, "Improving Background 11 | Subtraction using Local Binary Similarity Patterns", in WACV 2014, or G.-A. Bilodeau et al, "Change Detection 12 | in Feature Space Using Local Binary Similarity Patterns", in CRV 2013. 13 | 14 | This algorithm is currently NOT thread-safe. 15 | */ 16 | class BackgroundSubtractorLBSP : public cv::BackgroundSubtractor { 17 | public: 18 | //! full constructor 19 | BackgroundSubtractorLBSP(float fRelLBSPThreshold, size_t nLBSPThresholdOffset=0); 20 | //! default destructor 21 | virtual ~BackgroundSubtractorLBSP(); 22 | //! (re)initiaization method; needs to be called before starting background subtraction 23 | virtual void initialize(const cv::Mat& oInitImg); 24 | //! (re)initiaization method; needs to be called before starting background subtraction 25 | virtual void initialize(const cv::Mat& oInitImg, const cv::Mat& oROI)=0; 26 | //! primary model update function; the learning param is used to override the internal learning speed (ignored when <= 0) 27 | virtual void operator()(cv::InputArray image, cv::OutputArray fgmask, double learningRate=0)=0; 28 | //! unused, always returns nullptr 29 | virtual cv::AlgorithmInfo* info() const; 30 | //! returns a copy of the ROI used for descriptor extraction 31 | virtual cv::Mat getROICopy() const; 32 | //! sets the ROI to be used for descriptor extraction (note: this function will reinit the model and return the usable ROI) 33 | virtual void setROI(cv::Mat& oROI); 34 | //! turns automatic model reset on or off 35 | void setAutomaticModelReset(bool); 36 | 37 | protected: 38 | struct PxInfoBase { 39 | int nImgCoord_Y; 40 | int nImgCoord_X; 41 | size_t nModelIdx; 42 | }; 43 | //! background model ROI used for LBSP descriptor extraction (specific to the input image size) 44 | cv::Mat m_oROI; 45 | //! input image size 46 | cv::Size m_oImgSize; 47 | //! input image channel size 48 | size_t m_nImgChannels; 49 | //! input image type 50 | int m_nImgType; 51 | //! LBSP internal threshold offset value, used to reduce texture noise in dark regions 52 | const size_t m_nLBSPThresholdOffset; 53 | //! LBSP relative internal threshold (kept here since we don't keep an LBSP object) 54 | const float m_fRelLBSPThreshold; 55 | //! total number of pixels (depends on the input frame size) & total number of relevant pixels 56 | size_t m_nTotPxCount, m_nTotRelevantPxCount; 57 | //! current frame index, frame count since last model reset & model reset cooldown counters 58 | size_t m_nFrameIndex, m_nFramesSinceLastReset, m_nModelResetCooldown; 59 | //! pre-allocated internal LBSP threshold values LUT for all possible 8-bit intensities 60 | size_t m_anLBSPThreshold_8bitLUT[UCHAR_MAX+1]; 61 | //! internal pixel index LUT for all relevant analysis regions (based on the provided ROI) 62 | size_t* m_aPxIdxLUT; 63 | //! internal pixel info LUT for all possible pixel indexes 64 | PxInfoBase* m_aPxInfoLUT; 65 | //! default kernel size for median blur post-proc filtering 66 | const int m_nDefaultMedianBlurKernelSize; 67 | //! specifies whether the algorithm is fully initialized or not 68 | bool m_bInitialized; 69 | //! specifies whether automatic model resets are enabled or not 70 | bool m_bAutoModelResetEnabled; 71 | //! specifies whether the camera is considered moving or not 72 | bool m_bUsingMovingCamera; 73 | //! copy of latest pixel intensities (used when refreshing model) 74 | cv::Mat m_oLastColorFrame; 75 | //! copy of latest descriptors (used when refreshing model) 76 | cv::Mat m_oLastDescFrame; 77 | //! the foreground mask generated by the method at [t-1] 78 | cv::Mat m_oLastFGMask; 79 | 80 | public: 81 | // ######## DEBUG PURPOSES ONLY ########## 82 | int nDebugCoordX, nDebugCoordY; 83 | std::string sDebugName; 84 | }; 85 | 86 | -------------------------------------------------------------------------------- /BackgroundSubtractorSuBSENSE.cpp: -------------------------------------------------------------------------------- 1 | #include "BackgroundSubtractorSuBSENSE.h" 2 | #include "DistanceUtils.h" 3 | #include "RandUtils.h" 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | /* 10 | ******************Note that the main alogrithm of WeSamBE is in this file. ************** 11 | * Intrinsic parameters for our method are defined here; tuning these for better 12 | * performance should not be required in most cases -- although improvements in 13 | * very specific scenarios are always possible. 14 | * 15 | */ 16 | //! defines the threshold value(s) used to detect long-term ghosting and trigger the fast edge-based absorption heuristic 17 | #define GHOSTDET_D_MAX (0.010f) // defines 'negligible' change here 18 | #define GHOSTDET_S_MIN (0.995f) // defines the required minimum local foreground saturation value 19 | //! parameter used to scale dynamic distance threshold adjustments ('R(x)') 20 | #define FEEDBACK_R_VAR (0.01f) 21 | //! parameters used to adjust the variation step size of 'v(x)' 22 | #define FEEDBACK_V_INCR (1.000f) 23 | #define FEEDBACK_V_DECR (0.100f) 24 | //! parameters used to scale dynamic learning rate adjustments ('T(x)') 25 | #define FEEDBACK_T_DECR (0.2500f) 26 | #define FEEDBACK_T_INCR (0.5000f) 27 | #define FEEDBACK_T_LOWER (2.0000f) 28 | #define FEEDBACK_T_UPPER (256.00f) 29 | //! parameters used to define 'unstable' regions, based on segm noise/bg dynamics and local dist threshold values 30 | #define UNSTABLE_REG_RATIO_MIN (0.100f) 31 | #define UNSTABLE_REG_RDIST_MIN (3.000f) 32 | //! parameters used to scale the relative LBSP intensity threshold used for internal comparisons 33 | #define LBSPDESC_NONZERO_RATIO_MIN (0.100f) 34 | #define LBSPDESC_NONZERO_RATIO_MAX (0.500f) 35 | //! parameters used to define model reset/learning rate boosts in our frame-level component 36 | #define FRAMELEVEL_MIN_COLOR_DIFF_THRESHOLD (m_nMinColorDistThreshold/2) 37 | #define FRAMELEVEL_ANALYSIS_DOWNSAMPLE_RATIO (8) 38 | 39 | // local define used to display debug information 40 | #define DISPLAY_SUBSENSE_DEBUG_INFO 0 41 | // local define used to specify the default frame size (320x240 = QVGA) 42 | #define DEFAULT_FRAME_SIZE cv::Size(320,240) 43 | // local define used to specify the color dist threshold offset used for unstable regions 44 | #define STAB_COLOR_DIST_OFFSET (m_nMinColorDistThreshold/5) 45 | // local define used to specify the desc dist threshold offset used for unstable regions 46 | #define UNSTAB_DESC_DIST_OFFSET (m_nDescDistThresholdOffset) 47 | 48 | static const size_t s_nColorMaxDataRange_1ch = UCHAR_MAX; 49 | static const size_t s_nDescMaxDataRange_1ch = LBSP::DESC_SIZE*8; 50 | static const size_t s_nColorMaxDataRange_3ch = s_nColorMaxDataRange_1ch*3; 51 | static const size_t s_nDescMaxDataRange_3ch = s_nDescMaxDataRange_1ch*3; 52 | 53 | BackgroundSubtractorSuBSENSE::BackgroundSubtractorSuBSENSE( float fRelLBSPThreshold 54 | ,size_t nDescDistThresholdOffset 55 | ,size_t nMinColorDistThreshold 56 | ,size_t nBGSamples 57 | ,size_t nRequiredBGSamples 58 | ,size_t nSamplesForMovingAvgs) 59 | : BackgroundSubtractorLBSP(fRelLBSPThreshold) 60 | ,m_nMinColorDistThreshold(nMinColorDistThreshold) 61 | ,m_nDescDistThresholdOffset(nDescDistThresholdOffset) 62 | ,m_nBGSamples(nBGSamples) 63 | ,m_nRequiredBGSamples(nRequiredBGSamples) 64 | ,m_nSamplesForMovingAvgs(nSamplesForMovingAvgs) 65 | ,m_fLastNonZeroDescRatio(0.0f) 66 | ,m_bLearningRateScalingEnabled(true) 67 | ,m_fCurrLearningRateLowerCap(FEEDBACK_T_LOWER) 68 | ,m_fCurrLearningRateUpperCap(FEEDBACK_T_UPPER) 69 | ,m_nMedianBlurKernelSize(m_nDefaultMedianBlurKernelSize) 70 | ,m_bUse3x3Spread(true) { 71 | CV_Assert(m_nBGSamples>0 && m_nRequiredBGSamples<=m_nBGSamples); 72 | CV_Assert(m_nMinColorDistThreshold>=STAB_COLOR_DIST_OFFSET); 73 | } 74 | 75 | BackgroundSubtractorSuBSENSE::~BackgroundSubtractorSuBSENSE() { 76 | if(m_aPxIdxLUT) 77 | delete[] m_aPxIdxLUT; 78 | if(m_aPxInfoLUT) 79 | delete[] m_aPxInfoLUT; 80 | } 81 | 82 | void BackgroundSubtractorSuBSENSE::initialize(const cv::Mat& oInitImg, const cv::Mat& oROI) { 83 | // == init 84 | CV_Assert(!oInitImg.empty() && oInitImg.cols>0 && oInitImg.rows>0); 85 | CV_Assert(oInitImg.isContinuous()); 86 | CV_Assert(oInitImg.type()==CV_8UC3 || oInitImg.type()==CV_8UC1); 87 | if(oInitImg.type()==CV_8UC3) { 88 | /*std::vector voInitImgChannels; 89 | voInitImgChannels.resize(3);*/ 90 | cv::Mat voInitImgChannels[3]; 91 | cv::split(oInitImg,voInitImgChannels); 92 | if(!cv::countNonZero((voInitImgChannels[0]!=voInitImgChannels[1])|(voInitImgChannels[2]!=voInitImgChannels[1]))) 93 | std::cout << std::endl << "\tBackgroundSubtractorSuBSENSE : Warning, grayscale images should always be passed in CV_8UC1 format for optimal performance." << std::endl; 94 | } 95 | 96 | //上为显示; 97 | 98 | 99 | cv::Mat oNewBGROI; 100 | if(oROI.empty() && (m_oROI.empty() || oROI.size()!=oInitImg.size())) { 101 | oNewBGROI.create(oInitImg.size(),CV_8UC1); 102 | oNewBGROI = cv::Scalar_(UCHAR_MAX); 103 | } 104 | else if(oROI.empty()) 105 | oNewBGROI = m_oROI;//m_oROI : background model ROI used for LBSP descriptor extraction (specific to the input image size); 106 | else { 107 | CV_Assert(oROI.size()==oInitImg.size() && oROI.type()==CV_8UC1); 108 | CV_Assert(cv::countNonZero((oROI0))==0); 109 | oNewBGROI = oROI.clone(); 110 | 111 | cv::Mat oTempROI; 112 | cv::dilate(oNewBGROI,oTempROI,cv::Mat(),cv::Point(-1,-1),LBSP::PATCH_SIZE/2);//dilate 113 | cv::bitwise_or(oNewBGROI,oTempROI/2,oNewBGROI); 114 | } 115 | const size_t nOrigROIPxCount = (size_t)cv::countNonZero(oNewBGROI); 116 | CV_Assert(nOrigROIPxCount>0); 117 | LBSP::validateROI(oNewBGROI); 118 | 119 | const size_t nFinalROIPxCount = (size_t)cv::countNonZero(oNewBGROI); 120 | CV_Assert(nFinalROIPxCount>0); 121 | m_oROI = oNewBGROI; 122 | 123 | m_oImgSize = oInitImg.size(); 124 | m_nImgType = oInitImg.type(); 125 | m_nImgChannels = oInitImg.channels(); 126 | m_nTotPxCount = m_oImgSize.area(); 127 | 128 | 129 | m_nTotRelevantPxCount = nFinalROIPxCount; 130 | m_nFrameIndex = 0; 131 | m_nFramesSinceLastReset = 0; 132 | m_nModelResetCooldown = 0; 133 | m_fLastNonZeroDescRatio = 0.0f; 134 | 135 | const int nTotImgPixels = m_oImgSize.height*m_oImgSize.width; 136 | 137 | 138 | if(nOrigROIPxCount>=m_nTotPxCount/2 && (int)m_nTotPxCount>=DEFAULT_FRAME_SIZE.area()) { 139 | m_bLearningRateScalingEnabled = true; 140 | m_bAutoModelResetEnabled = true; 141 | m_bUse3x3Spread = !(nTotImgPixels>DEFAULT_FRAME_SIZE.area()*2); 142 | const int nRawMedianBlurKernelSize = std::min((int)floor((float)nTotImgPixels/DEFAULT_FRAME_SIZE.area()+0.5f)+m_nDefaultMedianBlurKernelSize,14); 143 | m_nMedianBlurKernelSize = (nRawMedianBlurKernelSize%2)?nRawMedianBlurKernelSize:nRawMedianBlurKernelSize-1; 144 | m_fCurrLearningRateLowerCap = FEEDBACK_T_LOWER; 145 | m_fCurrLearningRateUpperCap = FEEDBACK_T_UPPER; 146 | } 147 | else { 148 | m_bLearningRateScalingEnabled = false; 149 | m_bAutoModelResetEnabled = false; 150 | m_bUse3x3Spread = true; 151 | m_nMedianBlurKernelSize = m_nDefaultMedianBlurKernelSize; 152 | m_fCurrLearningRateLowerCap = FEEDBACK_T_LOWER*2; 153 | m_fCurrLearningRateUpperCap = FEEDBACK_T_UPPER*2; 154 | } 155 | m_oUpdateRateFrame.create(m_oImgSize,CV_32FC1); //T(x); 156 | m_oUpdateRateFrame = cv::Scalar(m_fCurrLearningRateLowerCap); 157 | m_oDistThresholdFrame.create(m_oImgSize,CV_32FC1); 158 | m_oDistThresholdFrame = cv::Scalar(1.0f); // R(x); 159 | m_oVariationModulatorFrame.create(m_oImgSize,CV_32FC1);//relative value used to modulate 'R(x)' and 'T(x)' variations; 160 | m_oVariationModulatorFrame = cv::Scalar(10.0f); // should always be >= FEEDBACK_V_DECR; 161 | m_oMeanLastDistFrame.create(m_oImgSize,CV_32FC1); //'D_last(x)', used to detect ghosts and high variation regions in the sequence; 162 | m_oMeanLastDistFrame = cv::Scalar(0.0f); 163 | m_oMeanMinDistFrame_LT.create(m_oImgSize,CV_32FC1);//per-pixel mean minimal distances from the model ('D_min(x)' in PBAS, used to control variation magnitude and direction of 'T(x)' and 'R(x)'); 164 | m_oMeanMinDistFrame_LT = cv::Scalar(0.0f); 165 | m_oMeanMinDistFrame_ST.create(m_oImgSize,CV_32FC1); 166 | m_oMeanMinDistFrame_ST = cv::Scalar(0.0f); 167 | 168 | 169 | 170 | m_oDownSampledFrameSize = cv::Size(m_oImgSize.width/FRAMELEVEL_ANALYSIS_DOWNSAMPLE_RATIO,m_oImgSize.height/FRAMELEVEL_ANALYSIS_DOWNSAMPLE_RATIO); 171 | m_oMeanDownSampledLastDistFrame_LT.create(m_oDownSampledFrameSize,CV_32FC((int)m_nImgChannels)); 172 | m_oMeanDownSampledLastDistFrame_LT = cv::Scalar(0.0f); 173 | m_oMeanDownSampledLastDistFrame_ST.create(m_oDownSampledFrameSize,CV_32FC((int)m_nImgChannels)); 174 | m_oMeanDownSampledLastDistFrame_ST = cv::Scalar(0.0f); 175 | m_oMeanRawSegmResFrame_LT.create(m_oImgSize,CV_32FC1); 176 | m_oMeanRawSegmResFrame_LT = cv::Scalar(0.0f); 177 | m_oMeanRawSegmResFrame_ST.create(m_oImgSize,CV_32FC1); 178 | m_oMeanRawSegmResFrame_ST = cv::Scalar(0.0f); 179 | m_oMeanFinalSegmResFrame_LT.create(m_oImgSize,CV_32FC1); 180 | m_oMeanFinalSegmResFrame_LT = cv::Scalar(0.0f); 181 | m_oMeanFinalSegmResFrame_ST.create(m_oImgSize,CV_32FC1); 182 | m_oMeanFinalSegmResFrame_ST = cv::Scalar(0.0f); 183 | 184 | 185 | m_oUnstableRegionMask.create(m_oImgSize,CV_8UC1);//a lookup map used to keep track of unstable regions (based on segm. noise & local dist. thresholds) 186 | m_oUnstableRegionMask = cv::Scalar_(0); 187 | m_oBlinksFrame.create(m_oImgSize,CV_8UC1);// per-pixel blink detection map ('Z(x)') 188 | m_oBlinksFrame = cv::Scalar_(0); 189 | m_oDownSampledFrame_MotionAnalysis.create(m_oDownSampledFrameSize,CV_8UC((int)m_nImgChannels));// pre-allocated matrix used to downsample the input frame when needed 190 | m_oDownSampledFrame_MotionAnalysis = cv::Scalar_::all(0); 191 | m_oLastColorFrame.create(m_oImgSize,CV_8UC((int)m_nImgChannels)); 192 | 193 | m_oLastColorFrame = cv::Scalar_::all(0);//copy of latest pixel intensities (used when refreshing model) 194 | m_oLastDescFrame.create(m_oImgSize,CV_16UC((int)m_nImgChannels)); 195 | m_oLastDescFrame = cv::Scalar_::all(0);//copy of latest descriptor 196 | m_oLastRawFGMask.create(m_oImgSize,CV_8UC1); 197 | m_oLastRawFGMask = cv::Scalar_(0);//the foreground mask generated by the method at [t-1] (without post-proc, used for blinking px detection) 198 | m_oLastFGMask.create(m_oImgSize,CV_8UC1); 199 | m_oLastFGMask = cv::Scalar_(0);// the foreground mask generated by the method at [t-1] 200 | m_oLastFGMask_dilated.create(m_oImgSize,CV_8UC1); 201 | m_oLastFGMask_dilated = cv::Scalar_(0); 202 | m_oLastFGMask_dilated_inverted.create(m_oImgSize,CV_8UC1); 203 | m_oLastFGMask_dilated_inverted = cv::Scalar_(0); 204 | m_oFGMask_FloodedHoles.create(m_oImgSize,CV_8UC1); 205 | m_oFGMask_FloodedHoles = cv::Scalar_(0); 206 | m_oFGMask_PreFlood.create(m_oImgSize,CV_8UC1); 207 | m_oFGMask_PreFlood = cv::Scalar_(0); 208 | m_oCurrRawFGBlinkMask.create(m_oImgSize,CV_8UC1); 209 | m_oCurrRawFGBlinkMask = cv::Scalar_(0); 210 | m_oLastRawFGBlinkMask.create(m_oImgSize,CV_8UC1); 211 | m_oLastRawFGBlinkMask = cv::Scalar_(0); 212 | effectPix.create(1,m_nBGSamples,CV_8UC1); 213 | effectPix = cv::Scalar_(0); 214 | 215 | 216 | m_voBGColorSamples.resize(m_nBGSamples); //background model pixel color intensity samples (equivalent to 'B(x)' in PBAS) 217 | m_voBGDescSamples.resize(m_nBGSamples);//(m_nBGSamples=N); 218 | 219 | for(size_t s=0; s::all(0); 222 | m_voBGDescSamples[s].create(m_oImgSize,CV_16UC((int)m_nImgChannels)); 223 | m_voBGDescSamples[s] = cv::Scalar_::all(0); 224 | } 225 | if(m_aPxIdxLUT) 226 | delete[] m_aPxIdxLUT; 227 | if(m_aPxInfoLUT) 228 | delete[] m_aPxInfoLUT; 229 | m_aPxIdxLUT = new size_t[m_nTotRelevantPxCount];//total number of relevant pixels 230 | m_aPxInfoLUT = new PxInfoBase[m_nTotPxCount]; //total number of pixels (depends on the input frame size) 231 | 232 | //m_nImgChannels==3 233 | CV_Assert(m_oLastColorFrame.step.p[0]==(size_t)m_oImgSize.width*3 && m_oLastColorFrame.step.p[1]==3); 234 | CV_Assert(m_oLastDescFrame.step.p[0]==m_oLastColorFrame.step.p[0]*2 && m_oLastDescFrame.step.p[1]==m_oLastColorFrame.step.p[1]*2); 235 | 236 | 237 | for(size_t t=0; t<=UCHAR_MAX; ++t) // UCHAR_MAX=255; 238 | m_anLBSPThreshold_8bitLUT[t] = cv::saturate_cast(m_nLBSPThresholdOffset+t*m_fRelLBSPThreshold); 239 | //m_nLBSPThresholdOffset: LBSP internal threshold offset value, used to reduce texture noise in dark regions 240 | // m_fRelLBSPThreshold: LBSP relative internal threshold (kept here since we don't keep an LBSP object) 241 | //m_anLBSPThreshold_8bitLUT: previous-allocated internal LBSP threshold values LUT for all possible 8-bit intensities 242 | 243 | 244 | 245 | 246 | 247 | for(size_t nPxIter=0, nModelIter=0; nPxIter0.0f && fSamplesRefreshFrac<=1.0f); 279 | 280 | 281 | const size_t nModelsToRefresh = fSamplesRefreshFrac<1.0f?(size_t)(fSamplesRefreshFrac*m_nBGSamples):m_nBGSamples; 282 | //nModelsToRefresh=N,i.e. m_nBGSamples 283 | const size_t nRefreshStartPos = fSamplesRefreshFrac<1.0f?rand()%m_nBGSamples:0; 284 | //nRefreshStartPos=0 285 | 286 | //m_nImgChannels==3 287 | for(size_t nModelIter=0; nModelIterUNSTABLE_REG_RDIST_MIN || (*pfCurrMeanRawSegmRes_LT-*pfCurrMeanFinalSegmRes_LT)>UNSTABLE_REG_RATIO_MIN || (*pfCurrMeanRawSegmRes_ST-*pfCurrMeanFinalSegmRes_ST)>UNSTABLE_REG_RATIO_MIN)?1:0;//统计不稳定区域; 368 | size_t nSampleIdx=0, goodDist = 0, sumeffectPix=0; 369 | size_t weightCoe=0; 370 | while( goodDistnCurrSCColorDistThreshold) 379 | goto failedcheck3ch; 380 | const size_t nIntraDescDist = hdist(anCurrIntraDesc[c],anBGIntraDesc[c]); 381 | LBSP::computeSingleRGBDescriptor(oInputImg,anBGColor[c],nCurrImgCoord_X,nCurrImgCoord_Y,c,m_anLBSPThreshold_8bitLUT[anBGColor[c]],anCurrInterDesc[c]); 382 | const size_t nInterDescDist = hdist(anCurrInterDesc[c],anBGIntraDesc[c]); 383 | const size_t nDescDist = (nIntraDescDist+nInterDescDist)/2; 384 | const size_t nSumDist = std::min((nDescDist/2)*(s_nColorMaxDataRange_1ch/s_nDescMaxDataRange_1ch)+nColorDist,s_nColorMaxDataRange_1ch); 385 | if(nSumDist>nCurrSCColorDistThreshold) 386 | goto failedcheck3ch; 387 | nTotDescDist += nDescDist; 388 | nTotSumDist += nSumDist; 389 | } 390 | if(nTotDescDist>nCurrTotDescDistThreshold || nTotSumDist>nCurrTotColorDistThreshold) 391 | goto failedcheck3ch; 392 | if(nMinTotDescDist>nTotDescDist) 393 | nMinTotDescDist = nTotDescDist; 394 | if(nMinTotSumDist>nTotSumDist) 395 | nMinTotSumDist = nTotSumDist; 396 | goodDist += anBGColor[3]; 397 | effectPix.data[nSampleIdx] = 1; 398 | sumeffectPix += effectPix.data[nSampleIdx]; 399 | 400 | failedcheck3ch: 401 | nSampleIdx++; 402 | } 403 | const float fNormalizedLastDist = ((float)L1dist<3>(anLastColor,anCurrColor)/s_nColorMaxDataRange_3ch+(float)hdist<3>(anLastIntraDesc,anCurrIntraDesc)/s_nDescMaxDataRange_3ch)/2; 404 | *pfCurrMeanLastDist = (*pfCurrMeanLastDist)*(1.0f-fRollAvgFactor_ST) + fNormalizedLastDist*fRollAvgFactor_ST; 405 | 406 | 407 | if(goodDist < m_nRequiredBGSamples) { 408 | // == foreground 409 | const float fNormalizedMinDist = std::min(1.0f,((float)nMinTotSumDist/s_nColorMaxDataRange_3ch+(float)nMinTotDescDist/s_nDescMaxDataRange_3ch)/2 + (float)(m_nRequiredBGSamples-goodDist)/m_nRequiredBGSamples); 410 | *pfCurrMeanMinDist_LT = (*pfCurrMeanMinDist_LT)*(1.0f-fRollAvgFactor_LT) + fNormalizedMinDist*fRollAvgFactor_LT; 411 | *pfCurrMeanMinDist_ST = (*pfCurrMeanMinDist_ST)*(1.0f-fRollAvgFactor_ST) + fNormalizedMinDist*fRollAvgFactor_ST; 412 | *pfCurrMeanRawSegmRes_LT = (*pfCurrMeanRawSegmRes_LT)*(1.0f-fRollAvgFactor_LT) + fRollAvgFactor_LT; 413 | *pfCurrMeanRawSegmRes_ST = (*pfCurrMeanRawSegmRes_ST)*(1.0f-fRollAvgFactor_ST) + fRollAvgFactor_ST; 414 | oCurrFGMask.data[nPxIter] = UCHAR_MAX; 415 | if(m_nModelResetCooldown && (rand()%(size_t)FEEDBACK_T_LOWER)==0) { 416 | const size_t s_rand = rand()%m_nBGSamples; 417 | for(size_t c=0; c<3; ++c) { 418 | *((ushort*)(m_voBGDescSamples[s_rand].data+nDescIterRGB+2*c)) = anCurrIntraDesc[c]; 419 | *(m_voBGColorSamples[s_rand].data+nPxIterRGB_1+c) = anCurrColor[c]; 420 | } 421 | 422 | 423 | } 424 | } 425 | else { 426 | // == background 427 | const float fNormalizedMinDist = ((float)nMinTotSumDist/s_nColorMaxDataRange_3ch+(float)nMinTotDescDist/s_nDescMaxDataRange_3ch)/2; 428 | *pfCurrMeanMinDist_LT = (*pfCurrMeanMinDist_LT)*(1.0f-fRollAvgFactor_LT) + fNormalizedMinDist*fRollAvgFactor_LT; 429 | *pfCurrMeanMinDist_ST = (*pfCurrMeanMinDist_ST)*(1.0f-fRollAvgFactor_ST) + fNormalizedMinDist*fRollAvgFactor_ST; 430 | *pfCurrMeanRawSegmRes_LT = (*pfCurrMeanRawSegmRes_LT)*(1.0f-fRollAvgFactor_LT); 431 | *pfCurrMeanRawSegmRes_ST = (*pfCurrMeanRawSegmRes_ST)*(1.0f-fRollAvgFactor_ST); 432 | const size_t nLearningRate = learningRateOverride>0?(size_t)ceil(learningRateOverride):(size_t)ceil(*pfCurrLearningRate); 433 | 434 | if((rand()%nLearningRate)==0) { 435 | 436 | for(size_t ms=0; ms < m_nBGSamples; ++ms) { 437 | if (effectPix.data[ms] == 1) { 438 | *(m_voBGColorSamples[ms].data+nPxIterRGB_1+3) += 1/sumeffectPix; 439 | } 440 | else { 441 | *(m_voBGColorSamples[ms].data+nPxIterRGB_1+3) -= 1/(m_nBGSamples-sumeffectPix); 442 | if (*(m_voBGColorSamples[ms].data+nPxIterRGB_1+3) < 0) *(m_voBGColorSamples[ms].data+nPxIterRGB_1+3) = 0; 443 | } 444 | } 445 | 446 | 447 | size_t mt=0; 448 | size_t weightmax = *(m_voBGColorSamples[0].data+nPxIterRGB_1+3); 449 | size_t weightmin = *(m_voBGColorSamples[0].data+nPxIterRGB_1+3); 450 | size_t weightmaxdot=0, weightmindot=0; 451 | while( mt < m_nBGSamples ) { 452 | if ( weightmax < (*(m_voBGColorSamples[mt].data+nPxIterRGB_1+3))){ 453 | weightmax=(*(m_voBGColorSamples[mt].data+nPxIterRGB_1+3)); 454 | weightmaxdot = mt; 455 | } 456 | if ( weightmin > (*(m_voBGColorSamples[mt].data+nPxIterRGB_1+3))){ 457 | weightmin=(*(m_voBGColorSamples[mt].data+nPxIterRGB_1+3)); 458 | weightmindot = mt; 459 | } 460 | ++mt; 461 | } 462 | //const size_t s_rand = rand()%m_nBGSamples; 463 | for(size_t c=0; c<3; ++c) { 464 | *((ushort*)(m_voBGDescSamples[weightmindot].data+nDescIterRGB+2*c)) = anCurrIntraDesc[c]; 465 | *(m_voBGColorSamples[weightmindot].data+nPxIterRGB_1+c) = anCurrColor[c]; 466 | } 467 | *(m_voBGColorSamples[weightmindot].data+nPxIterRGB_1+3) += 1; 468 | size_t count_weight=0; 469 | for (size_t m_y=0; m_y < m_nBGSamples; ++m_y) { 470 | if ((*(m_voBGColorSamples[m_y].data+nPxIterRGB_1+3)) > (weightCoe*weightmax)) ++count_weight; 471 | } 472 | 473 | 474 | for (size_t m_z=0; m_z < m_nBGSamples; ++m_z) { 475 | if ((*(m_voBGColorSamples[m_z].data+nPxIterRGB_1+3)) > (weightCoe*weightmax)) { 476 | 477 | *(m_voBGColorSamples[m_z].data+nPxIterRGB_1+3) -= 1/count_weight; 478 | } 479 | } 480 | size_t countTotalWeight=0; 481 | for (size_t m_s=0; m_s < m_nBGSamples; ++m_s) { 482 | countTotalWeight += *(m_voBGColorSamples[m_s].data+nPxIterRGB_1+3); 483 | } 484 | if (countTotalWeight != (m_nBGSamples+5) ){ 485 | *(m_voBGColorSamples[weightmaxdot].data+nPxIterRGB_1+3) += (m_nBGSamples+5-countTotalWeight); 486 | 487 | } 488 | } 489 | 490 | int nSampleImgCoord_Y, nSampleImgCoord_X; 491 | const bool bCurrUsing3x3Spread = m_bUse3x3Spread && !m_oUnstableRegionMask.data[nPxIter]; 492 | if(bCurrUsing3x3Spread) 493 | getRandNeighborPosition_3x3(nSampleImgCoord_X,nSampleImgCoord_Y,nCurrImgCoord_X,nCurrImgCoord_Y,LBSP::PATCH_SIZE/2,m_oImgSize); 494 | else 495 | getRandNeighborPosition_5x5(nSampleImgCoord_X,nSampleImgCoord_Y,nCurrImgCoord_X,nCurrImgCoord_Y,LBSP::PATCH_SIZE/2,m_oImgSize); 496 | const size_t n_rand = rand(); 497 | const size_t idx_rand_uchar = m_oImgSize.width*nSampleImgCoord_Y + nSampleImgCoord_X; 498 | const size_t idx_rand_flt32 = idx_rand_uchar*4; 499 | const float fRandMeanLastDist = *((float*)(m_oMeanLastDistFrame.data+idx_rand_flt32)); 500 | const float fRandMeanRawSegmRes = *((float*)(m_oMeanRawSegmResFrame_ST.data+idx_rand_flt32)); 501 | 502 | if((n_rand%(bCurrUsing3x3Spread?nLearningRate:(nLearningRate/2+1)))==0 503 | || (fRandMeanRawSegmRes>GHOSTDET_S_MIN && fRandMeanLastDist (*(m_voBGColorSamples[mt].data+idx_rand_uchar_rgb_1+3))){ 517 | weightmin=(*(m_voBGColorSamples[mt].data+idx_rand_uchar_rgb_1+3)); 518 | weightmindot = mt; 519 | } 520 | ++mt; 521 | } 522 | for(size_t c=0; c<3; ++c) { 523 | *((ushort*)(m_voBGDescSamples[weightmindot].data+idx_rand_ushrt_rgb+2*c)) = anCurrIntraDesc[c]; 524 | 525 | *(m_voBGColorSamples[weightmindot].data+idx_rand_uchar_rgb_1+c) = anCurrColor[c]; 526 | } 527 | *(m_voBGColorSamples[weightmindot].data+idx_rand_uchar_rgb_1+3) +=1; 528 | //const size_t s_rand = rand()%m_nBGSamples; 529 | size_t count_weight=0; 530 | for (size_t m_y=0; m_y < m_nBGSamples; ++m_y) { 531 | if ((*(m_voBGColorSamples[m_y].data+idx_rand_uchar_rgb_1+3)) > (weightCoe*weightmax)) ++count_weight; 532 | } 533 | 534 | // count_weight=m_nBGSamples; 535 | 536 | for (size_t m_z=0; m_z < m_nBGSamples; ++m_z) { 537 | if ((*(m_voBGColorSamples[m_z].data+idx_rand_uchar_rgb_1+3)) > (weightCoe*weightmax)) { 538 | 539 | *(m_voBGColorSamples[m_z].data+idx_rand_uchar_rgb_1+3) -= 1/count_weight; 540 | } 541 | } 542 | size_t countTotalWeight=0; 543 | for (size_t m_s=0; m_s < m_nBGSamples; ++m_s) { 544 | countTotalWeight += *(m_voBGColorSamples[m_s].data+idx_rand_uchar_rgb_1+3); 545 | } 546 | if (countTotalWeight != (m_nBGSamples+5) ){ 547 | *(m_voBGColorSamples[weightmaxdot].data+idx_rand_uchar_rgb_1+3) += (m_nBGSamples+5-countTotalWeight); 548 | } 549 | } 550 | } 551 | if(m_oLastFGMask.data[nPxIter] || (std::min(*pfCurrMeanMinDist_LT,*pfCurrMeanMinDist_ST)m_fCurrLearningRateLowerCap) 556 | *pfCurrLearningRate -= FEEDBACK_T_DECR*(*pfCurrVariationFactor)/std::max(*pfCurrMeanMinDist_LT,*pfCurrMeanMinDist_ST); 557 | if((*pfCurrLearningRate)m_fCurrLearningRateUpperCap) 560 | *pfCurrLearningRate = m_fCurrLearningRateUpperCap; 561 | if(std::max(*pfCurrMeanMinDist_LT,*pfCurrMeanMinDist_ST)>UNSTABLE_REG_RATIO_MIN && m_oBlinksFrame.data[nPxIter]) 562 | (*pfCurrVariationFactor) += FEEDBACK_V_INCR; 563 | else if((*pfCurrVariationFactor)>FEEDBACK_V_DECR) { 564 | (*pfCurrVariationFactor) -= m_oLastFGMask.data[nPxIter]?FEEDBACK_V_DECR/4:m_oUnstableRegionMask.data[nPxIter]?FEEDBACK_V_DECR/2:FEEDBACK_V_DECR; 565 | if((*pfCurrVariationFactor)(anCurrIntraDesc)>=4) 576 | ++nNonZeroDescCount; 577 | for(size_t c=0; c<3; ++c) { 578 | anLastIntraDesc[c] = anCurrIntraDesc[c]; 579 | anLastColor[c] = anCurrColor[c]; 580 | } 581 | } 582 | 583 | #if DISPLAY_SUBSENSE_DEBUG_INFO 584 | std::cout << std::endl; 585 | cv::Point dbgpt(nDebugCoordX,nDebugCoordY); 586 | cv::Mat oMeanMinDistFrameNormalized; m_oMeanMinDistFrame_ST.copyTo(oMeanMinDistFrameNormalized); 587 | cv::circle(oMeanMinDistFrameNormalized,dbgpt,5,cv::Scalar(1.0f)); 588 | cv::resize(oMeanMinDistFrameNormalized,oMeanMinDistFrameNormalized,DEFAULT_FRAME_SIZE); 589 | cv::imshow("d_min(x)",oMeanMinDistFrameNormalized); 590 | std::cout << std::fixed << std::setprecision(5) << " d_min(" << dbgpt << ") = " << m_oMeanMinDistFrame_ST.at(dbgpt) << std::endl; 591 | cv::Mat oMeanLastDistFrameNormalized; m_oMeanLastDistFrame.copyTo(oMeanLastDistFrameNormalized); 592 | cv::circle(oMeanLastDistFrameNormalized,dbgpt,5,cv::Scalar(1.0f)); 593 | cv::resize(oMeanLastDistFrameNormalized,oMeanLastDistFrameNormalized,DEFAULT_FRAME_SIZE); 594 | cv::imshow("d_last(x)",oMeanLastDistFrameNormalized); 595 | std::cout << std::fixed << std::setprecision(5) << " d_last(" << dbgpt << ") = " << m_oMeanLastDistFrame.at(dbgpt) << std::endl; 596 | cv::Mat oMeanRawSegmResFrameNormalized; m_oMeanRawSegmResFrame_ST.copyTo(oMeanRawSegmResFrameNormalized); 597 | cv::circle(oMeanRawSegmResFrameNormalized,dbgpt,5,cv::Scalar(1.0f)); 598 | cv::resize(oMeanRawSegmResFrameNormalized,oMeanRawSegmResFrameNormalized,DEFAULT_FRAME_SIZE); 599 | cv::imshow("s_avg(x)",oMeanRawSegmResFrameNormalized); 600 | std::cout << std::fixed << std::setprecision(5) << " s_avg(" << dbgpt << ") = " << m_oMeanRawSegmResFrame_ST.at(dbgpt) << std::endl; 601 | cv::Mat oMeanFinalSegmResFrameNormalized; m_oMeanFinalSegmResFrame_ST.copyTo(oMeanFinalSegmResFrameNormalized); 602 | cv::circle(oMeanFinalSegmResFrameNormalized,dbgpt,5,cv::Scalar(1.0f)); 603 | cv::resize(oMeanFinalSegmResFrameNormalized,oMeanFinalSegmResFrameNormalized,DEFAULT_FRAME_SIZE); 604 | cv::imshow("z_avg(x)",oMeanFinalSegmResFrameNormalized); 605 | std::cout << std::fixed << std::setprecision(5) << " z_avg(" << dbgpt << ") = " << m_oMeanFinalSegmResFrame_ST.at(dbgpt) << std::endl; 606 | cv::Mat oDistThresholdFrameNormalized; m_oDistThresholdFrame.convertTo(oDistThresholdFrameNormalized,CV_32FC1,0.25f,-0.25f); 607 | cv::circle(oDistThresholdFrameNormalized,dbgpt,5,cv::Scalar(1.0f)); 608 | cv::resize(oDistThresholdFrameNormalized,oDistThresholdFrameNormalized,DEFAULT_FRAME_SIZE); 609 | cv::imshow("r(x)",oDistThresholdFrameNormalized); 610 | std::cout << std::fixed << std::setprecision(5) << " r(" << dbgpt << ") = " << m_oDistThresholdFrame.at(dbgpt) << std::endl; 611 | cv::Mat oVariationModulatorFrameNormalized; cv::normalize(m_oVariationModulatorFrame,oVariationModulatorFrameNormalized,0,255,cv::NORM_MINMAX,CV_8UC1); 612 | cv::circle(oVariationModulatorFrameNormalized,dbgpt,5,cv::Scalar(255)); 613 | cv::resize(oVariationModulatorFrameNormalized,oVariationModulatorFrameNormalized,DEFAULT_FRAME_SIZE); 614 | cv::imshow("v(x)",oVariationModulatorFrameNormalized); 615 | std::cout << std::fixed << std::setprecision(5) << " v(" << dbgpt << ") = " << m_oVariationModulatorFrame.at(dbgpt) << std::endl; 616 | cv::Mat oUpdateRateFrameNormalized; m_oUpdateRateFrame.convertTo(oUpdateRateFrameNormalized,CV_32FC1,1.0f/FEEDBACK_T_UPPER,-FEEDBACK_T_LOWER/FEEDBACK_T_UPPER); 617 | cv::circle(oUpdateRateFrameNormalized,dbgpt,5,cv::Scalar(1.0f)); 618 | cv::resize(oUpdateRateFrameNormalized,oUpdateRateFrameNormalized,DEFAULT_FRAME_SIZE); 619 | cv::imshow("t(x)",oUpdateRateFrameNormalized); 620 | std::cout << std::fixed << std::setprecision(5) << " t(" << dbgpt << ") = " << m_oUpdateRateFrame.at(dbgpt) << std::endl; 621 | #endif //DISPLAY_SUBSENSE_DEBUG_INFO 622 | cv::bitwise_xor(oCurrFGMask,m_oLastRawFGMask,m_oCurrRawFGBlinkMask); 623 | cv::bitwise_or(m_oCurrRawFGBlinkMask,m_oLastRawFGBlinkMask,m_oBlinksFrame); 624 | m_oCurrRawFGBlinkMask.copyTo(m_oLastRawFGBlinkMask); 625 | oCurrFGMask.copyTo(m_oLastRawFGMask); 626 | cv::morphologyEx(oCurrFGMask,m_oFGMask_PreFlood,cv::MORPH_CLOSE,cv::Mat()); 627 | m_oFGMask_PreFlood.copyTo(m_oFGMask_FloodedHoles); 628 | cv::floodFill(m_oFGMask_FloodedHoles,cv::Point(0,0),UCHAR_MAX); 629 | cv::bitwise_not(m_oFGMask_FloodedHoles,m_oFGMask_FloodedHoles); 630 | cv::erode(m_oFGMask_PreFlood,m_oFGMask_PreFlood,cv::Mat(),cv::Point(-1,-1),3); 631 | cv::bitwise_or(oCurrFGMask,m_oFGMask_FloodedHoles,oCurrFGMask); 632 | cv::bitwise_or(oCurrFGMask,m_oFGMask_PreFlood,oCurrFGMask); 633 | cv::medianBlur(oCurrFGMask,m_oLastFGMask,m_nMedianBlurKernelSize); 634 | cv::dilate(m_oLastFGMask,m_oLastFGMask_dilated,cv::Mat(),cv::Point(-1,-1),3); 635 | cv::bitwise_and(m_oBlinksFrame,m_oLastFGMask_dilated_inverted,m_oBlinksFrame); 636 | cv::bitwise_not(m_oLastFGMask_dilated,m_oLastFGMask_dilated_inverted); 637 | cv::bitwise_and(m_oBlinksFrame,m_oLastFGMask_dilated_inverted,m_oBlinksFrame); 638 | m_oLastFGMask.copyTo(oCurrFGMask); 639 | cv::addWeighted(m_oMeanFinalSegmResFrame_LT,(1.0f-fRollAvgFactor_LT),m_oLastFGMask,(1.0/UCHAR_MAX)*fRollAvgFactor_LT,0,m_oMeanFinalSegmResFrame_LT,CV_32F); 640 | cv::addWeighted(m_oMeanFinalSegmResFrame_ST,(1.0f-fRollAvgFactor_ST),m_oLastFGMask,(1.0/UCHAR_MAX)*fRollAvgFactor_ST,0,m_oMeanFinalSegmResFrame_ST,CV_32F); 641 | const float fCurrNonZeroDescRatio = (float)nNonZeroDescCount/m_nTotRelevantPxCount; 642 | if(fCurrNonZeroDescRatiocv::saturate_cast(m_nLBSPThresholdOffset+ceil(t*m_fRelLBSPThreshold/4))) 645 | --m_anLBSPThreshold_8bitLUT[t]; 646 | } 647 | else if(fCurrNonZeroDescRatio>LBSPDESC_NONZERO_RATIO_MAX && m_fLastNonZeroDescRatio>LBSPDESC_NONZERO_RATIO_MAX) { 648 | for(size_t t=0; t<=UCHAR_MAX; ++t) 649 | if(m_anLBSPThreshold_8bitLUT[t](m_nLBSPThresholdOffset+UCHAR_MAX*m_fRelLBSPThreshold)) 650 | ++m_anLBSPThreshold_8bitLUT[t]; 651 | } 652 | m_fLastNonZeroDescRatio = fCurrNonZeroDescRatio; 653 | if(m_bLearningRateScalingEnabled) { 654 | cv::resize(oInputImg,m_oDownSampledFrame_MotionAnalysis,m_oDownSampledFrameSize,0,0,cv::INTER_AREA); 655 | cv::accumulateWeighted(m_oDownSampledFrame_MotionAnalysis,m_oMeanDownSampledLastDistFrame_LT,fRollAvgFactor_LT); 656 | cv::accumulateWeighted(m_oDownSampledFrame_MotionAnalysis,m_oMeanDownSampledLastDistFrame_ST,fRollAvgFactor_ST); 657 | size_t nTotColorDiff = 0; 658 | for(int i=0; i1000) 673 | m_bAutoModelResetEnabled = false; 674 | else if(fCurrColorDiffRatio>=FRAMELEVEL_MIN_COLOR_DIFF_THRESHOLD && m_nModelResetCooldown==0) { 675 | m_nFramesSinceLastReset = 0; 676 | refreshModel(0.1f); // reset 10% of the bg model 677 | m_nModelResetCooldown = m_nSamplesForMovingAvgs/4; 678 | m_oUpdateRateFrame = cv::Scalar(1.0f); 679 | } 680 | else 681 | ++m_nFramesSinceLastReset; 682 | } 683 | else if(fCurrColorDiffRatio>=FRAMELEVEL_MIN_COLOR_DIFF_THRESHOLD*2) { 684 | m_nFramesSinceLastReset = 0; 685 | m_bAutoModelResetEnabled = true; 686 | } 687 | if(fCurrColorDiffRatio>=FRAMELEVEL_MIN_COLOR_DIFF_THRESHOLD/2) { 688 | m_fCurrLearningRateLowerCap = (float)std::max((int)FEEDBACK_T_LOWER>>(int)(fCurrColorDiffRatio/2),1); 689 | m_fCurrLearningRateUpperCap = (float)std::max((int)FEEDBACK_T_UPPER>>(int)(fCurrColorDiffRatio/2),1); 690 | } 691 | else { 692 | m_fCurrLearningRateLowerCap = FEEDBACK_T_LOWER; 693 | m_fCurrLearningRateUpperCap = FEEDBACK_T_UPPER; 694 | } 695 | if(m_nModelResetCooldown>0) 696 | --m_nModelResetCooldown; 697 | } 698 | } 699 | 700 | 701 | 702 | 703 | /*void BackgroundSubtractorSuBSENSE::getBackgroundImage(cv::OutputArray backgroundImage) const { 704 | CV_Assert(m_bInitialized); 705 | cv::Mat oAvgBGImg = cv::Mat::zeros(m_oImgSize,CV_32FC(((int)m_nImgChannels))); 706 | for(size_t s=0; s m_voBGColorSamples; 77 | //! background model descriptors samples 78 | std::vector m_voBGDescSamples; 79 | 80 | //! per-pixel update rates ('T(x)' in PBAS, which contains pixel-level 'sigmas', as referred to in ViBe) 81 | cv::Mat m_oUpdateRateFrame; 82 | //! per-pixel distance thresholds (equivalent to 'R(x)' in PBAS, but used as a relative value to determine both intensity and descriptor variation thresholds) 83 | cv::Mat m_oDistThresholdFrame; 84 | //! per-pixel distance variation modulators ('v(x)', relative value used to modulate 'R(x)' and 'T(x)' variations) 85 | cv::Mat m_oVariationModulatorFrame; 86 | //! per-pixel mean distances between consecutive frames ('D_last(x)', used to detect ghosts and high variation regions in the sequence) 87 | cv::Mat m_oMeanLastDistFrame; 88 | //! per-pixel mean minimal distances from the model ('D_min(x)' in PBAS, used to control variation magnitude and direction of 'T(x)' and 'R(x)') 89 | cv::Mat m_oMeanMinDistFrame_LT, m_oMeanMinDistFrame_ST; 90 | //! per-pixel mean downsampled distances between consecutive frames (used to analyze camera movement and control max learning rates globally) 91 | cv::Mat m_oMeanDownSampledLastDistFrame_LT, m_oMeanDownSampledLastDistFrame_ST; 92 | //! per-pixel mean raw segmentation results (used to detect unstable segmentation regions) 93 | cv::Mat m_oMeanRawSegmResFrame_LT, m_oMeanRawSegmResFrame_ST; 94 | //! per-pixel mean raw segmentation results (used to detect unstable segmentation regions) 95 | cv::Mat m_oMeanFinalSegmResFrame_LT, m_oMeanFinalSegmResFrame_ST; 96 | //! a lookup map used to keep track of unstable regions (based on segm. noise & local dist. thresholds) 97 | cv::Mat m_oUnstableRegionMask; 98 | //! per-pixel blink detection map ('Z(x)') 99 | cv::Mat m_oBlinksFrame; 100 | //! pre-allocated matrix used to downsample the input frame when needed 101 | cv::Mat m_oDownSampledFrame_MotionAnalysis; 102 | //! the foreground mask generated by the method at [t-1] (without post-proc, used for blinking px detection) 103 | cv::Mat m_oLastRawFGMask; 104 | 105 | //! pre-allocated CV_8UC1 matrices used to speed up morph ops 106 | cv::Mat m_oFGMask_PreFlood; 107 | cv::Mat m_oFGMask_FloodedHoles; 108 | cv::Mat m_oLastFGMask_dilated; 109 | cv::Mat m_oLastFGMask_dilated_inverted; 110 | cv::Mat m_oCurrRawFGBlinkMask; 111 | cv::Mat m_oLastRawFGBlinkMask; 112 | cv::Mat effectPix; 113 | }; 114 | 115 | -------------------------------------------------------------------------------- /DistanceUtils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | //! computes the L1 distance between two integer values 6 | template static inline typename std::enable_if::value,size_t>::type L1dist(T a, T b) { 7 | return (size_t)abs((int)a-b); 8 | } 9 | 10 | //! computes the L1 distance between two float values 11 | template static inline typename std::enable_if::value,float>::type L1dist(T a, T b) { 12 | return fabs((float)a-(float)b); 13 | } 14 | 15 | //! computes the L1 distance between two generic arrays 16 | template static inline auto L1dist(const T* a, const T* b) -> decltype(L1dist(*a,*b)) { 17 | decltype(L1dist(*a,*b)) oResult = 0; 18 | for(size_t c=0; c static inline auto L1dist(const T* a, const T* b, size_t nElements, const uchar* m=NULL) -> decltype(L1dist(a,b)) { 25 | decltype(L1dist(a,b)) oResult = 0; 26 | size_t nTotElements = nElements*nChannels; 27 | if(m) { 28 | for(size_t n=0,i=0; n(a+n,b+n); 31 | } 32 | else { 33 | for(size_t n=0; n(a+n,b+n); 35 | } 36 | return oResult; 37 | } 38 | 39 | //! computes the L1 distance between two generic arrays 40 | template static inline auto L1dist(const T* a, const T* b, size_t nElements, size_t nChannels, const uchar* m=NULL) -> decltype(L1dist<3>(a,b,nElements,m)) { 41 | CV_Assert(nChannels>0 && nChannels<=4); 42 | switch(nChannels) { 43 | case 1: return L1dist<1>(a,b,nElements,m); 44 | case 2: return L1dist<2>(a,b,nElements,m); 45 | case 3: return L1dist<3>(a,b,nElements,m); 46 | case 4: return L1dist<4>(a,b,nElements,m); 47 | default: return 0; 48 | } 49 | } 50 | 51 | //! computes the L1 distance between two opencv vectors 52 | template static inline auto L1dist_(const cv::Vec& a, const cv::Vec& b) -> decltype(L1dist((T*)(0),(T*)(0))) { 53 | T a_array[nChannels], b_array[nChannels]; 54 | for(size_t c=0; c(a_array,b_array); 59 | } 60 | 61 | /////////////////////////////////////////////////////////////////////////////////////////////////// 62 | 63 | //! computes the squared L2 distance between two generic variables 64 | template static inline auto L2sqrdist(T a, T b) -> decltype(L1dist(a,b)) { 65 | auto oResult = L1dist(a,b); 66 | return oResult*oResult; 67 | } 68 | 69 | //! computes the squared L2 distance between two generic arrays 70 | template static inline auto L2sqrdist(const T* a, const T* b) -> decltype(L2sqrdist(*a,*b)) { 71 | decltype(L2sqrdist(*a,*b)) oResult = 0; 72 | for(size_t c=0; c static inline auto L2sqrdist(const T* a, const T* b, size_t nElements, const uchar* m=NULL) -> decltype(L2sqrdist(a,b)) { 79 | decltype(L2sqrdist(a,b)) oResult = 0; 80 | size_t nTotElements = nElements*nChannels; 81 | if(m) { 82 | for(size_t n=0,i=0; n(a+n,b+n); 85 | } 86 | else { 87 | for(size_t n=0; n(a+n,b+n); 89 | } 90 | return oResult; 91 | } 92 | 93 | //! computes the squared L2 distance between two generic arrays 94 | template static inline auto L2sqrdist(const T* a, const T* b, size_t nElements, size_t nChannels, const uchar* m=NULL) -> decltype(L2sqrdist<3>(a,b,nElements,m)) { 95 | CV_Assert(nChannels>0 && nChannels<=4); 96 | switch(nChannels) { 97 | case 1: return L2sqrdist<1>(a,b,nElements,m); 98 | case 2: return L2sqrdist<2>(a,b,nElements,m); 99 | case 3: return L2sqrdist<3>(a,b,nElements,m); 100 | case 4: return L2sqrdist<4>(a,b,nElements,m); 101 | default: return 0; 102 | } 103 | } 104 | 105 | //! computes the squared L2 distance between two opencv vectors 106 | template static inline auto L2sqrdist_(const cv::Vec& a, const cv::Vec& b) -> decltype(L2sqrdist((T*)(0),(T*)(0))) { 107 | T a_array[nChannels], b_array[nChannels]; 108 | for(size_t c=0; c(a_array,b_array); 113 | } 114 | 115 | //! computes the L2 distance between two generic arrays 116 | template static inline float L2dist(const T* a, const T* b) { 117 | decltype(L2sqrdist(*a,*b)) oResult = 0; 118 | for(size_t c=0; c static inline float L2dist(const T* a, const T* b, size_t nElements, const uchar* m=NULL) { 125 | decltype(L2sqrdist(a,b)) oResult = 0; 126 | size_t nTotElements = nElements*nChannels; 127 | if(m) { 128 | for(size_t n=0,i=0; n(a+n,b+n); 131 | } 132 | else { 133 | for(size_t n=0; n(a+n,b+n); 135 | } 136 | return sqrt((float)oResult); 137 | } 138 | 139 | //! computes the squared L2 distance between two generic arrays 140 | template static inline float L2dist(const T* a, const T* b, size_t nElements, size_t nChannels, const uchar* m=NULL) { 141 | CV_Assert(nChannels>0 && nChannels<=4); 142 | switch(nChannels) { 143 | case 1: return L2dist<1>(a,b,nElements,m); 144 | case 2: return L2dist<2>(a,b,nElements,m); 145 | case 3: return L2dist<3>(a,b,nElements,m); 146 | case 4: return L2dist<4>(a,b,nElements,m); 147 | default: return 0; 148 | } 149 | } 150 | 151 | //! computes the L2 distance between two opencv vectors 152 | template static inline float L2dist_(const cv::Vec& a, const cv::Vec& b) { 153 | T a_array[nChannels], b_array[nChannels]; 154 | for(size_t c=0; c(a_array,b_array); 159 | } 160 | 161 | /////////////////////////////////////////////////////////////////////////////////////////////////// 162 | 163 | //! computes the color distortion between two integer arrays 164 | template static inline typename std::enable_if::value,size_t>::type cdist(const T* curr, const T* bg) { 165 | static_assert(nChannels>1,"cdist: requires more than one channel"); 166 | size_t curr_sqr = 0; 167 | bool bSkip = true; 168 | for(size_t c=0; c static inline typename std::enable_if::value,float>::type cdist(const T* curr, const T* bg) { 185 | static_assert(nChannels>1,"cdist: requires more than one channel"); 186 | float curr_sqr = 0; 187 | bool bSkip = true; 188 | for(size_t c=0; c static inline auto cdist(const T* a, const T* b, size_t nElements, const uchar* m=NULL) -> decltype(cdist(a,b)) { 205 | decltype(cdist(a,b)) oResult = 0; 206 | size_t nTotElements = nElements*nChannels; 207 | if(m) { 208 | for(size_t n=0,i=0; n(a+n,b+n); 211 | } 212 | else { 213 | for(size_t n=0; n(a+n,b+n); 215 | } 216 | return oResult; 217 | } 218 | 219 | //! computes the color distortion between two generic arrays 220 | template static inline auto cdist(const T* a, const T* b, size_t nElements, size_t nChannels, const uchar* m=NULL) -> decltype(cdist<3>(a,b,nElements,m)) { 221 | CV_Assert(nChannels>1 && nChannels<=4); 222 | switch(nChannels) { 223 | case 2: return cdist<2>(a,b,nElements,m); 224 | case 3: return cdist<3>(a,b,nElements,m); 225 | case 4: return cdist<4>(a,b,nElements,m); 226 | default: return 0; 227 | } 228 | } 229 | 230 | //! computes the color distortion between two opencv vectors 231 | template static inline auto cdist_(const cv::Vec& a, const cv::Vec& b) -> decltype(cdist((T*)(0),(T*)(0))) { 232 | T a_array[nChannels], b_array[nChannels]; 233 | for(size_t c=0; c(a_array,b_array); 238 | } 239 | 240 | //! computes a color distortion-distance mix using two generic distances 241 | template static inline T cmixdist(T oL1Distance, T oCDistortion) { 242 | return (oL1Distance/2+oCDistortion*4); 243 | } 244 | 245 | //! computes a color distoirtion-distance mix using two generic arrays 246 | template static inline typename std::enable_if::value,size_t>::type cmixdist(const T* curr, const T* bg) { 247 | return cmixdist(L1dist(curr,bg),cdist(curr,bg)); 248 | } 249 | 250 | template static inline typename std::enable_if::value,float>::type cmixdist(const T* curr, const T* bg) { 251 | return cmixdist(L1dist(curr,bg),cdist(curr,bg)); 252 | } 253 | 254 | /////////////////////////////////////////////////////////////////////////////////////////////////// 255 | 256 | //! popcount LUT for 8-bit vectors 257 | static const uchar popcount_LUT8[256] = { 258 | 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 259 | 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 260 | 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 261 | 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 262 | 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 263 | 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 264 | 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 265 | 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 266 | 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 267 | 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 268 | 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 269 | 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 270 | 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 271 | 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 272 | 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 273 | 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8, 274 | }; 275 | 276 | //! computes the population count of an N-byte vector using an 8-bit popcount LUT 277 | template static inline size_t popcount(T x) { 278 | size_t nBytes = sizeof(T); 279 | size_t nResult = 0; 280 | for(size_t l=0; l>l*8)]; 282 | return nResult; 283 | } 284 | 285 | //! computes the hamming distance between two N-byte vectors using an 8-bit popcount LUT 286 | template static inline size_t hdist(T a, T b) { 287 | return popcount(a^b); 288 | } 289 | 290 | //! computes the gradient magnitude distance between two N-byte vectors using an 8-bit popcount LUT 291 | template static inline size_t gdist(T a, T b) { 292 | return L1dist(popcount(a),popcount(b)); 293 | } 294 | 295 | //! computes the population count of a (nChannels*N)-byte vector using an 8-bit popcount LUT 296 | template static inline size_t popcount(const T* x) { 297 | size_t nBytes = sizeof(T); 298 | size_t nResult = 0; 299 | for(size_t c=0; c>l*8)]; 302 | return nResult; 303 | } 304 | 305 | //! computes the hamming distance between two (nChannels*N)-byte vectors using an 8-bit popcount LUT 306 | template static inline size_t hdist(const T* a, const T* b) { 307 | T xor_array[nChannels]; 308 | for(size_t c=0; c(xor_array); 311 | } 312 | 313 | //! computes the gradient magnitude distance between two (nChannels*N)-byte vectors using an 8-bit popcount LUT 314 | template static inline size_t gdist(const T* a, const T* b) { 315 | return L1dist(popcount(a),popcount(b)); 316 | } 317 | -------------------------------------------------------------------------------- /LBSP.cpp: -------------------------------------------------------------------------------- 1 | #include "LBSP.h" 2 | 3 | LBSP::LBSP(size_t nThreshold) 4 | : m_bOnlyUsingAbsThreshold(true) 5 | ,m_fRelThreshold(0) // unused 6 | ,m_nThreshold(nThreshold) 7 | ,m_oRefImage() {} 8 | 9 | LBSP::LBSP(float fRelThreshold, size_t nThresholdOffset) 10 | : m_bOnlyUsingAbsThreshold(false) 11 | ,m_fRelThreshold(fRelThreshold) 12 | ,m_nThreshold(nThresholdOffset) 13 | ,m_oRefImage() { 14 | CV_Assert(m_fRelThreshold>=0); 15 | } 16 | 17 | LBSP::~LBSP() {} 18 | 19 | void LBSP::read(const cv::FileNode& /*fn*/) { 20 | // ... = fn["..."]; 21 | } 22 | 23 | void LBSP::write(cv::FileStorage& /*fs*/) const { 24 | //fs << "..." << ...; 25 | } 26 | 27 | void LBSP::setReference(const cv::Mat& img) { 28 | CV_DbgAssert(img.empty() || img.type()==CV_8UC1 || img.type()==CV_8UC3); 29 | m_oRefImage = img; 30 | } 31 | 32 | int LBSP::descriptorSize() const { 33 | return DESC_SIZE; 34 | } 35 | 36 | int LBSP::descriptorType() const { 37 | return CV_16U; 38 | } 39 | 40 | bool LBSP::isUsingRelThreshold() const { 41 | return !m_bOnlyUsingAbsThreshold; 42 | } 43 | 44 | float LBSP::getRelThreshold() const { 45 | return m_fRelThreshold; 46 | } 47 | 48 | size_t LBSP::getAbsThreshold() const { 49 | return m_nThreshold; 50 | } 51 | 52 | static inline void lbsp_computeImpl( const cv::Mat& oInputImg, 53 | const cv::Mat& oRefImg, 54 | const std::vector& voKeyPoints, 55 | cv::Mat& oDesc, 56 | size_t _t) { 57 | CV_DbgAssert(oRefImg.empty() || (oRefImg.size==oInputImg.size && oRefImg.type()==oInputImg.type())); 58 | CV_DbgAssert(oInputImg.type()==CV_8UC1 || oInputImg.type()==CV_8UC3); 59 | CV_DbgAssert(LBSP::DESC_SIZE==2); // @@@ also relies on a constant desc size 60 | const size_t nChannels = (size_t)oInputImg.channels(); 61 | const size_t _step_row = oInputImg.step.p[0]; 62 | const uchar* _data = oInputImg.data; 63 | const uchar* _refdata = oRefImg.empty()?oInputImg.data:oRefImg.data; 64 | const size_t nKeyPoints = voKeyPoints.size(); 65 | if(nChannels==1) { 66 | oDesc.create((int)nKeyPoints,1,CV_16UC1); 67 | for(size_t k=0; k((int)k); 72 | #include "LBSP_16bits_dbcross_1ch.i" 73 | } 74 | } 75 | else { //nChannels==3 76 | oDesc.create((int)nKeyPoints,1,CV_16UC3); 77 | for(size_t k=0; k& voKeyPoints, 90 | cv::Mat& oDesc, 91 | float fThreshold, 92 | size_t nThresholdOffset) { 93 | CV_DbgAssert(oRefImg.empty() || (oRefImg.size==oInputImg.size && oRefImg.type()==oInputImg.type())); 94 | CV_DbgAssert(oInputImg.type()==CV_8UC1 || oInputImg.type()==CV_8UC3); 95 | CV_DbgAssert(LBSP::DESC_SIZE==2); // @@@ also relies on a constant desc size 96 | CV_DbgAssert(fThreshold>=0); 97 | const size_t nChannels = (size_t)oInputImg.channels(); 98 | const size_t _step_row = oInputImg.step.p[0]; 99 | const uchar* _data = oInputImg.data; 100 | const uchar* _refdata = oRefImg.empty()?oInputImg.data:oRefImg.data; 101 | const size_t nKeyPoints = voKeyPoints.size(); 102 | if(nChannels==1) { 103 | oDesc.create((int)nKeyPoints,1,CV_16UC1); 104 | for(size_t k=0; k((int)k); 109 | const size_t _t = (size_t)(_ref*fThreshold)+nThresholdOffset; 110 | #include "LBSP_16bits_dbcross_1ch.i" 111 | } 112 | } 113 | else { //nChannels==3 114 | oDesc.create((int)nKeyPoints,1,CV_16UC3); 115 | for(size_t k=0; k& voKeyPoints, 129 | cv::Mat& oDesc, 130 | size_t _t) { 131 | CV_DbgAssert(oRefImg.empty() || (oRefImg.size==oInputImg.size && oRefImg.type()==oInputImg.type())); 132 | CV_DbgAssert(oInputImg.type()==CV_8UC1 || oInputImg.type()==CV_8UC3); 133 | CV_DbgAssert(LBSP::DESC_SIZE==2); // @@@ also relies on a constant desc size 134 | const size_t nChannels = (size_t)oInputImg.channels(); 135 | const size_t _step_row = oInputImg.step.p[0]; 136 | const uchar* _data = oInputImg.data; 137 | const uchar* _refdata = oRefImg.empty()?oInputImg.data:oRefImg.data; 138 | const size_t nKeyPoints = voKeyPoints.size(); 139 | if(nChannels==1) { 140 | oDesc.create(oInputImg.size(),CV_16UC1); 141 | for(size_t k=0; k(_y,_x); 146 | #include "LBSP_16bits_dbcross_1ch.i" 147 | } 148 | } 149 | else { //nChannels==3 150 | oDesc.create(oInputImg.size(),CV_16UC3); 151 | for(size_t k=0; k& voKeyPoints, 164 | cv::Mat& oDesc, 165 | float fThreshold, 166 | size_t nThresholdOffset) { 167 | CV_DbgAssert(oRefImg.empty() || (oRefImg.size==oInputImg.size && oRefImg.type()==oInputImg.type())); 168 | CV_DbgAssert(oInputImg.type()==CV_8UC1 || oInputImg.type()==CV_8UC3); 169 | CV_DbgAssert(LBSP::DESC_SIZE==2); // @@@ also relies on a constant desc size 170 | CV_DbgAssert(fThreshold>=0); 171 | const size_t nChannels = (size_t)oInputImg.channels(); 172 | const size_t _step_row = oInputImg.step.p[0]; 173 | const uchar* _data = oInputImg.data; 174 | const uchar* _refdata = oRefImg.empty()?oInputImg.data:oRefImg.data; 175 | const size_t nKeyPoints = voKeyPoints.size(); 176 | if(nChannels==1) { 177 | oDesc.create(oInputImg.size(),CV_16UC1); 178 | for(size_t k=0; k(_y,_x); 183 | const size_t _t = (size_t)(_ref*fThreshold)+nThresholdOffset; 184 | #include "LBSP_16bits_dbcross_1ch.i" 185 | } 186 | } 187 | else { //nChannels==3 188 | oDesc.create(oInputImg.size(),CV_16UC3); 189 | for(size_t k=0; k& voKeypoints, cv::Mat& oDescriptors) const { 201 | CV_Assert(!oImage.empty()); 202 | cv::KeyPointsFilter::runByImageBorder(voKeypoints,oImage.size(),PATCH_SIZE/2); 203 | cv::KeyPointsFilter::runByKeypointSize(voKeypoints,std::numeric_limits::epsilon()); 204 | if(voKeypoints.empty()) { 205 | oDescriptors.release(); 206 | return; 207 | } 208 | if(m_bOnlyUsingAbsThreshold) 209 | lbsp_computeImpl2(oImage,m_oRefImage,voKeypoints,oDescriptors,m_nThreshold); 210 | else 211 | lbsp_computeImpl2(oImage,m_oRefImage,voKeypoints,oDescriptors,m_fRelThreshold,m_nThreshold); 212 | } 213 | 214 | void LBSP::compute2(const std::vector& voImageCollection, std::vector >& vvoPointCollection, std::vector& voDescCollection) const { 215 | CV_Assert(voImageCollection.size() == vvoPointCollection.size()); 216 | voDescCollection.resize(voImageCollection.size()); 217 | for(size_t i=0; i& voKeypoints, cv::Mat& oDescriptors) const { 222 | CV_Assert(!oImage.empty()); 223 | cv::KeyPointsFilter::runByImageBorder(voKeypoints,oImage.size(),PATCH_SIZE/2); 224 | cv::KeyPointsFilter::runByKeypointSize(voKeypoints,std::numeric_limits::epsilon()); 225 | if(voKeypoints.empty()) { 226 | oDescriptors.release(); 227 | return; 228 | } 229 | if(m_bOnlyUsingAbsThreshold) 230 | lbsp_computeImpl(oImage,m_oRefImage,voKeypoints,oDescriptors,m_nThreshold); 231 | else 232 | lbsp_computeImpl(oImage,m_oRefImage,voKeypoints,oDescriptors,m_fRelThreshold,m_nThreshold); 233 | } 234 | 235 | void LBSP::reshapeDesc(cv::Size oSize, const std::vector& voKeypoints, const cv::Mat& oDescriptors, cv::Mat& oOutput) { 236 | CV_DbgAssert(!voKeypoints.empty()); 237 | CV_DbgAssert(!oDescriptors.empty() && oDescriptors.cols==1); 238 | CV_DbgAssert(oSize.width>0 && oSize.height>0); 239 | CV_DbgAssert(DESC_SIZE==2); // @@@ also relies on a constant desc size 240 | CV_DbgAssert(oDescriptors.type()==CV_16UC1 || oDescriptors.type()==CV_16UC3); 241 | const size_t nChannels = (size_t)oDescriptors.channels(); 242 | const size_t nKeyPoints = voKeypoints.size(); 243 | if(nChannels==1) { 244 | oOutput.create(oSize,CV_16UC1); 245 | oOutput = cv::Scalar_(0); 246 | for(size_t k=0; k(voKeypoints[k].pt) = oDescriptors.at((int)k); 248 | } 249 | else { //nChannels==3 250 | oOutput.create(oSize,CV_16UC3); 251 | oOutput = cv::Scalar_(0,0,0); 252 | for(size_t k=0; k(i,j) = (uchar)(fScaleFactor*hdist(desc1_ptr[j],desc2_ptr[j])); 281 | } 282 | } 283 | else { //nChannels==3 284 | if(bForceMergeChannels) 285 | oOutput.create(oDesc1.size(),CV_8UC1); 286 | else 287 | oOutput.create(oDesc1.size(),CV_8UC3); 288 | oOutput = cv::Scalar::all(0); 289 | for(int i=0; i& voKeypoints, cv::Size oImgSize) { 308 | cv::KeyPointsFilter::runByImageBorder(voKeypoints,oImgSize,PATCH_SIZE/2); 309 | } 310 | 311 | void LBSP::validateROI(cv::Mat& oROI) { 312 | CV_Assert(!oROI.empty() && oROI.type()==CV_8UC1); 313 | cv::Mat oROI_new(oROI.size(),CV_8UC1,cv::Scalar_(0)); 314 | const size_t nBorderSize = PATCH_SIZE/2; 315 | const cv::Rect nROI_inner(nBorderSize,nBorderSize,oROI.cols-nBorderSize*2,oROI.rows-nBorderSize*2); 316 | cv::Mat(oROI,nROI_inner).copyTo(cv::Mat(oROI_new,nROI_inner)); 317 | oROI = oROI_new; 318 | } 319 | -------------------------------------------------------------------------------- /LBSP.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include "DistanceUtils.h" 7 | 8 | /*! 9 | Local Binary Similarity Pattern (LBSP) feature extractor 10 | 11 | Note 1: both grayscale and RGB/BGR images may be used with this extractor. 12 | Note 2: using LBSP::compute2(...) is logically equivalent to using LBSP::compute(...) followed by LBSP::reshapeDesc(...). 13 | 14 | For more details on the different parameters, see G.-A. Bilodeau et al, "Change Detection in Feature Space Using Local 15 | Binary Similarity Patterns", in CRV 2013. 16 | 17 | This algorithm is currently NOT thread-safe. 18 | */ 19 | class LBSP : public cv::DescriptorExtractor { 20 | public: 21 | //! constructor 1, threshold = absolute intensity 'similarity' threshold used when computing comparisons 22 | LBSP(size_t nThreshold); 23 | //! constructor 2, threshold = relative intensity 'similarity' threshold used when computing comparisons 24 | LBSP(float fRelThreshold, size_t nThresholdOffset=0); 25 | //! default destructor 26 | virtual ~LBSP(); 27 | //! loads extractor params from the specified file node @@@@ not impl 28 | virtual void read(const cv::FileNode&); 29 | //! writes extractor params to the specified file storage @@@@ not impl 30 | virtual void write(cv::FileStorage&) const; 31 | //! sets the 'reference' image to be used for inter-frame comparisons (note: if no image is set or if the image is empty, the algorithm will default back to intra-frame comparisons) 32 | virtual void setReference(const cv::Mat&); 33 | //! returns the current descriptor size, in bytes 34 | virtual int descriptorSize() const; 35 | //! returns the current descriptor data type 36 | virtual int descriptorType() const; 37 | //! returns whether this extractor is using a relative threshold or not 38 | virtual bool isUsingRelThreshold() const; 39 | //! returns the current relative threshold used for comparisons (-1 = invalid/not used) 40 | virtual float getRelThreshold() const; 41 | //! returns the current absolute threshold used for comparisons (-1 = invalid/not used) 42 | virtual size_t getAbsThreshold() const; 43 | 44 | //! similar to DescriptorExtractor::compute(const cv::Mat& image, ...), but in this case, the descriptors matrix has the same shape as the input matrix (possibly slower, but the result can be displayed) 45 | void compute2(const cv::Mat& oImage, std::vector& voKeypoints, cv::Mat& oDescriptors) const; 46 | //! batch version of LBSP::compute2(const cv::Mat& image, ...), also similar to DescriptorExtractor::compute(const std::vector& imageCollection, ...) 47 | void compute2(const std::vector& voImageCollection, std::vector >& vvoPointCollection, std::vector& voDescCollection) const; 48 | 49 | //! utility function, shortcut/lightweight/direct single-point LBSP computation function for extra flexibility (1-channel version) 50 | inline static void computeGrayscaleDescriptor(const cv::Mat& oInputImg, const uchar _ref, const int _x, const int _y, const size_t _t, ushort& _res) { 51 | CV_DbgAssert(!oInputImg.empty()); 52 | CV_DbgAssert(oInputImg.type()==CV_8UC1); 53 | CV_DbgAssert(LBSP::DESC_SIZE==2); // @@@ also relies on a constant desc size 54 | CV_DbgAssert(_x>=(int)LBSP::PATCH_SIZE/2 && _y>=(int)LBSP::PATCH_SIZE/2); 55 | CV_DbgAssert(_x=(int)LBSP::PATCH_SIZE/2 && _y>=(int)LBSP::PATCH_SIZE/2); 67 | CV_DbgAssert(_x=(int)LBSP::PATCH_SIZE/2 && _y>=(int)LBSP::PATCH_SIZE/2); 79 | CV_DbgAssert(_x=(int)LBSP::PATCH_SIZE/2 && _y>=(int)LBSP::PATCH_SIZE/2); 91 | CV_DbgAssert(_x& voKeypoints, const cv::Mat& oDescriptors, cv::Mat& oOutput); 99 | //! utility function, used to illustrate the difference between two descriptor images 100 | static void calcDescImgDiff(const cv::Mat& oDesc1, const cv::Mat& oDesc2, cv::Mat& oOutput, bool bForceMergeChannels=false); 101 | //! utility function, used to filter out bad keypoints that would trigger out of bounds error because they're too close to the image border 102 | static void validateKeyPoints(std::vector& voKeypoints, cv::Size oImgSize); 103 | //! utility function, used to filter out bad pixels in a ROI that would trigger out of bounds error because they're too close to the image border 104 | static void validateROI(cv::Mat& oROI); 105 | //! utility, specifies the pixel size of the pattern used (width and height) 106 | static const size_t PATCH_SIZE = 5; 107 | //! utility, specifies the number of bytes per descriptor (should be the same as calling 'descriptorSize()') 108 | static const size_t DESC_SIZE = 2; 109 | 110 | protected: 111 | //! classic 'compute' implementation, based on the regular DescriptorExtractor::computeImpl arguments & expected output 112 | virtual void computeImpl(const cv::Mat& oImage, std::vector& voKeypoints, cv::Mat& oDescriptors) const; 113 | 114 | const bool m_bOnlyUsingAbsThreshold; 115 | const float m_fRelThreshold; 116 | const size_t m_nThreshold; 117 | cv::Mat m_oRefImage; 118 | }; 119 | -------------------------------------------------------------------------------- /LBSP_16bits_dbcross_1ch.i: -------------------------------------------------------------------------------- 1 | // note: this is the LBSP 16 bit double-cross single channel pattern as used in 2 | // the original article by G.-A. Bilodeau et al. 3 | // 4 | // O O O 4 .. 3 .. 6 5 | // O O O .. 15 8 13 .. 6 | // O O X O O => 0 9 X 11 1 7 | // O O O .. 12 10 14 .. 8 | // O O O 7 .. 2 .. 5 9 | // 10 | // 11 | // must be defined externally: 12 | // _t (size_t, absolute threshold used for comparisons) 13 | // _ref (uchar, 'central' value used for comparisons) 14 | // _data (uchar*, single-channel data to be covered by the pattern) 15 | // _y (int, pattern rows location in the image data) 16 | // _x (int, pattern cols location in the image data) 17 | // _step_row (size_t, step size between rows, including padding) 18 | // _res (ushort, 16 bit result vector) 19 | // L1dist (function, returns the absolute difference between two uchars) 20 | 21 | #ifdef _val 22 | #error "definitions clash detected" 23 | #else 24 | #define _val(x,y) _data[_step_row*(_y+y)+_x+x] 25 | #endif 26 | 27 | _res = ((L1dist(_val(-1, 1),_ref) > _t) << 15) 28 | + ((L1dist(_val( 1,-1),_ref) > _t) << 14) 29 | + ((L1dist(_val( 1, 1),_ref) > _t) << 13) 30 | + ((L1dist(_val(-1,-1),_ref) > _t) << 12) 31 | + ((L1dist(_val( 1, 0),_ref) > _t) << 11) 32 | + ((L1dist(_val( 0,-1),_ref) > _t) << 10) 33 | + ((L1dist(_val(-1, 0),_ref) > _t) << 9) 34 | + ((L1dist(_val( 0, 1),_ref) > _t) << 8) 35 | + ((L1dist(_val(-2,-2),_ref) > _t) << 7) 36 | + ((L1dist(_val( 2, 2),_ref) > _t) << 6) 37 | + ((L1dist(_val( 2,-2),_ref) > _t) << 5) 38 | + ((L1dist(_val(-2, 2),_ref) > _t) << 4) 39 | + ((L1dist(_val( 0, 2),_ref) > _t) << 3) 40 | + ((L1dist(_val( 0,-2),_ref) > _t) << 2) 41 | + ((L1dist(_val( 2, 0),_ref) > _t) << 1) 42 | + ((L1dist(_val(-2, 0),_ref) > _t)); 43 | 44 | #undef _val 45 | -------------------------------------------------------------------------------- /LBSP_16bits_dbcross_3ch1t.i: -------------------------------------------------------------------------------- 1 | // note: this is the LBSP 16 bit double-cross indiv RGB pattern as used in 2 | // the original article by G.-A. Bilodeau et al. 3 | // 4 | // O O O 4 .. 3 .. 6 5 | // O O O .. 15 8 13 .. 6 | // O O X O O => 0 9 X 11 1 7 | // O O O .. 12 10 14 .. 8 | // O O O 7 .. 2 .. 5 9 | // 3x 3x 10 | // 11 | // must be defined externally: 12 | // _t (size_t, absolute threshold used for comparisons) 13 | // _ref (uchar[3], 'central' values used for comparisons) 14 | // _data (uchar*, triple-channel data to be covered by the pattern) 15 | // _y (int, pattern rows location in the image data) 16 | // _x (int, pattern cols location in the image data) 17 | // _step_row (size_t, step size between rows, including padding) 18 | // _res (ushort[3], 16 bit result vectors vector) 19 | // L1dist (function, returns the absolute difference between two uchars) 20 | 21 | #ifdef _val 22 | #error "definitions clash detected" 23 | #else 24 | #define _val(x,y,n) _data[_step_row*(_y+y)+3*(_x+x)+n] 25 | #endif 26 | 27 | for(int n=0; n<3; ++n) { 28 | _res[n] = ((L1dist(_val(-1, 1, n),_ref[n]) > _t) << 15) 29 | + ((L1dist(_val( 1,-1, n),_ref[n]) > _t) << 14) 30 | + ((L1dist(_val( 1, 1, n),_ref[n]) > _t) << 13) 31 | + ((L1dist(_val(-1,-1, n),_ref[n]) > _t) << 12) 32 | + ((L1dist(_val( 1, 0, n),_ref[n]) > _t) << 11) 33 | + ((L1dist(_val( 0,-1, n),_ref[n]) > _t) << 10) 34 | + ((L1dist(_val(-1, 0, n),_ref[n]) > _t) << 9) 35 | + ((L1dist(_val( 0, 1, n),_ref[n]) > _t) << 8) 36 | + ((L1dist(_val(-2,-2, n),_ref[n]) > _t) << 7) 37 | + ((L1dist(_val( 2, 2, n),_ref[n]) > _t) << 6) 38 | + ((L1dist(_val( 2,-2, n),_ref[n]) > _t) << 5) 39 | + ((L1dist(_val(-2, 2, n),_ref[n]) > _t) << 4) 40 | + ((L1dist(_val( 0, 2, n),_ref[n]) > _t) << 3) 41 | + ((L1dist(_val( 0,-2, n),_ref[n]) > _t) << 2) 42 | + ((L1dist(_val( 2, 0, n),_ref[n]) > _t) << 1) 43 | + ((L1dist(_val(-2, 0, n),_ref[n]) > _t)); 44 | } 45 | 46 | #undef _val 47 | -------------------------------------------------------------------------------- /LBSP_16bits_dbcross_3ch3t.i: -------------------------------------------------------------------------------- 1 | // note: this is the LBSP 16 bit double-cross indiv RGB pattern as used in 2 | // the original article by G.-A. Bilodeau et al. 3 | // 4 | // O O O 4 .. 3 .. 6 5 | // O O O .. 15 8 13 .. 6 | // O O X O O => 0 9 X 11 1 7 | // O O O .. 12 10 14 .. 8 | // O O O 7 .. 2 .. 5 9 | // 3x 3x 10 | // 11 | // must be defined externally: 12 | // _t (size_t[3], absolute thresholds used for comparisons) 13 | // _ref (uchar[3], 'central' values used for comparisons) 14 | // _data (uchar*, triple-channel data to be covered by the pattern) 15 | // _y (int, pattern rows location in the image data) 16 | // _x (int, pattern cols location in the image data) 17 | // _step_row (size_t, step size between rows, including padding) 18 | // _res (ushort[3], 16 bit result vectors vector) 19 | // L1dist (function, returns the absolute difference between two uchars) 20 | 21 | #ifdef _val 22 | #error "definitions clash detected" 23 | #else 24 | #define _val(x,y,n) _data[_step_row*(_y+y)+3*(_x+x)+n] 25 | #endif 26 | 27 | for(int n=0; n<3; ++n) { 28 | _res[n] = ((L1dist(_val(-1, 1, n),_ref[n]) > _t[n]) << 15) 29 | + ((L1dist(_val( 1,-1, n),_ref[n]) > _t[n]) << 14) 30 | + ((L1dist(_val( 1, 1, n),_ref[n]) > _t[n]) << 13) 31 | + ((L1dist(_val(-1,-1, n),_ref[n]) > _t[n]) << 12) 32 | + ((L1dist(_val( 1, 0, n),_ref[n]) > _t[n]) << 11) 33 | + ((L1dist(_val( 0,-1, n),_ref[n]) > _t[n]) << 10) 34 | + ((L1dist(_val(-1, 0, n),_ref[n]) > _t[n]) << 9) 35 | + ((L1dist(_val( 0, 1, n),_ref[n]) > _t[n]) << 8) 36 | + ((L1dist(_val(-2,-2, n),_ref[n]) > _t[n]) << 7) 37 | + ((L1dist(_val( 2, 2, n),_ref[n]) > _t[n]) << 6) 38 | + ((L1dist(_val( 2,-2, n),_ref[n]) > _t[n]) << 5) 39 | + ((L1dist(_val(-2, 2, n),_ref[n]) > _t[n]) << 4) 40 | + ((L1dist(_val( 0, 2, n),_ref[n]) > _t[n]) << 3) 41 | + ((L1dist(_val( 0,-2, n),_ref[n]) > _t[n]) << 2) 42 | + ((L1dist(_val( 2, 0, n),_ref[n]) > _t[n]) << 1) 43 | + ((L1dist(_val(-2, 0, n),_ref[n]) > _t[n])); 44 | } 45 | 46 | #undef _val 47 | -------------------------------------------------------------------------------- /LBSP_16bits_dbcross_s3ch.i: -------------------------------------------------------------------------------- 1 | // note: this is the LBSP 16 bit double-cross indiv RGB pattern as used in 2 | // the original article by G.-A. Bilodeau et al. 3 | // 4 | // O O O 4 .. 3 .. 6 5 | // O O O .. 15 8 13 .. 6 | // O O X O O => 0 9 X 11 1 7 | // O O O .. 12 10 14 .. 8 | // O O O 7 .. 2 .. 5 9 | // (single/3x) (single/3x) 10 | // 11 | // must be defined externally: 12 | // _t (size_t, absolute threshold used for comparisons) 13 | // _ref (uchar, 'central' value used for comparisons) 14 | // _data (uchar*, triple-channel data to be covered by the pattern) 15 | // _y (int, pattern rows location in the image data) 16 | // _x (int, pattern cols location in the image data) 17 | // _c (size_t, pattern channel location in the image data) 18 | // _step_row (size_t, step size between rows, including padding) 19 | // _res (ushort, 16 bit result vector) 20 | // L1dist (function, returns the absolute difference between two uchars) 21 | 22 | #ifdef _val 23 | #error "definitions clash detected" 24 | #else 25 | #define _val(x,y,n) _data[_step_row*(_y+y)+3*(_x+x)+n] 26 | #endif 27 | 28 | _res = ((L1dist(_val(-1, 1, _c),_ref) > _t) << 15) 29 | + ((L1dist(_val( 1,-1, _c),_ref) > _t) << 14) 30 | + ((L1dist(_val( 1, 1, _c),_ref) > _t) << 13) 31 | + ((L1dist(_val(-1,-1, _c),_ref) > _t) << 12) 32 | + ((L1dist(_val( 1, 0, _c),_ref) > _t) << 11) 33 | + ((L1dist(_val( 0,-1, _c),_ref) > _t) << 10) 34 | + ((L1dist(_val(-1, 0, _c),_ref) > _t) << 9) 35 | + ((L1dist(_val( 0, 1, _c),_ref) > _t) << 8) 36 | + ((L1dist(_val(-2,-2, _c),_ref) > _t) << 7) 37 | + ((L1dist(_val( 2, 2, _c),_ref) > _t) << 6) 38 | + ((L1dist(_val( 2,-2, _c),_ref) > _t) << 5) 39 | + ((L1dist(_val(-2, 2, _c),_ref) > _t) << 4) 40 | + ((L1dist(_val( 0, 2, _c),_ref) > _t) << 3) 41 | + ((L1dist(_val( 0,-2, _c),_ref) > _t) << 2) 42 | + ((L1dist(_val( 2, 0, _c),_ref) > _t) << 1) 43 | + ((L1dist(_val(-2, 0, _c),_ref) > _t)); 44 | 45 | #undef _val 46 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WeSamBE: A Weight-Sample-Based Method for Background Subtraction(https://github.com/aimeng100/WeSamBE) 2 | 3 | If this code helps with your work/research, please consider citing 4 | 5 | Shengqin Jiang, Xiaobo Lu, WeSamBE: A Weight-Sample-Based Method for Background Subtraction**. 6 | IEEE Transactions on Circuits and Systems for Video Technology, 2018, 28(9):2105 - 2115. 7 | 8 | #######text##################### 9 | 10 | 11 | @article{jiang2017wesambe, 12 | title={WeSamBE: A weight-sample-based method for background subtraction}, 13 | author={Jiang, Shengqin and Lu, Xiaobo}, 14 | journal={IEEE Transactions on Circuits and Systems for Video Technology}, 15 | year={2017}, 16 | publisher={IEEE} 17 | } 18 | 19 | 20 | ## Pre-requisites 21 | This code has been tested on a Windows 10 (x64) system, C++ 2010 22 | 23 | 24 | ## References 25 | 26 | Shengqin Jiang and Xiaobo Lu. 27 | [WeSamBE: A Weight-Sample-Based Method for Background Subtraction.](http://ieeexplore.ieee.org/abstract/document/7938679/) 28 | 29 | 30 | ## Acknowledgements 31 | This code is based on the [SuBSENSE](https://bitbucket.org/pierre_luc_st_charles/subsense) 32 | so thanks to the original authors/maintainers for releasing the code. 33 | -------------------------------------------------------------------------------- /RandUtils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /*// gaussian 3x3 pattern, based on 'floor(fspecial('gaussian', 3, 1)*256)' 4 | static const int s_nSamplesInitPatternWidth = 3; 5 | static const int s_nSamplesInitPatternHeight = 3; 6 | static const int s_nSamplesInitPatternTot = 256; 7 | static const int s_anSamplesInitPattern[s_nSamplesInitPatternHeight][s_nSamplesInitPatternWidth] = { 8 | {19, 32, 19,}, 9 | {32, 52, 32,}, 10 | {19, 32, 19,}, 11 | };*/ 12 | 13 | // gaussian 7x7 pattern, based on 'floor(fspecial('gaussian',7,2)*512)' 14 | static const int s_nSamplesInitPatternWidth = 7; 15 | static const int s_nSamplesInitPatternHeight = 7; 16 | static const int s_nSamplesInitPatternTot = 512; 17 | static const int s_anSamplesInitPattern[s_nSamplesInitPatternHeight][s_nSamplesInitPatternWidth] = { 18 | {2, 4, 6, 7, 6, 4, 2,}, 19 | {4, 8, 12, 14, 12, 8, 4,}, 20 | {6, 12, 21, 25, 21, 12, 6,}, 21 | {7, 14, 25, 28, 25, 14, 7,}, 22 | {6, 12, 21, 25, 21, 12, 6,}, 23 | {4, 8, 12, 14, 12, 8, 4,}, 24 | {2, 4, 6, 7, 6, 4, 2,}, 25 | }; 26 | 27 | //! returns a random init/sampling position for the specified pixel position; also guards against out-of-bounds values via image/border size check. 28 | static inline void getRandSamplePosition(int& x_sample, int& y_sample, const int x_orig, const int y_orig, const int border, const cv::Size& imgsize) { 29 | int r = 1+rand()%s_nSamplesInitPatternTot; 30 | for(x_sample=0; x_sample=imgsize.width-border) 43 | x_sample = imgsize.width-border-1; 44 | if(y_sample=imgsize.height-border) 47 | y_sample = imgsize.height-border-1; 48 | } 49 | 50 | // simple 8-connected (3x3) neighbors pattern 51 | static const int s_anNeighborPatternSize_3x3 = 8; 52 | static const int s_anNeighborPattern_3x3[8][2] = { 53 | {-1, 1}, { 0, 1}, { 1, 1}, 54 | {-1, 0}, { 1, 0}, 55 | {-1,-1}, { 0,-1}, { 1,-1}, 56 | }; 57 | 58 | //! returns a random neighbor position for the specified pixel position; also guards against out-of-bounds values via image/border size check. 59 | static inline void getRandNeighborPosition_3x3(int& x_neighbor, int& y_neighbor, const int x_orig, const int y_orig, const int border, const cv::Size& imgsize) { 60 | int r = rand()%s_anNeighborPatternSize_3x3; 61 | x_neighbor = x_orig+s_anNeighborPattern_3x3[r][0]; 62 | y_neighbor = y_orig+s_anNeighborPattern_3x3[r][1]; 63 | if(x_neighbor=imgsize.width-border) 66 | x_neighbor = imgsize.width-border-1; 67 | if(y_neighbor=imgsize.height-border) 70 | y_neighbor = imgsize.height-border-1; 71 | } 72 | 73 | // 5x5 neighbors pattern 74 | static const int s_anNeighborPatternSize_5x5 = 24; 75 | static const int s_anNeighborPattern_5x5[24][2] = { 76 | {-2, 2}, {-1, 2}, { 0, 2}, { 1, 2}, { 2, 2}, 77 | {-2, 1}, {-1, 1}, { 0, 1}, { 1, 1}, { 2, 1}, 78 | {-2, 0}, {-1, 0}, { 1, 0}, { 2, 0}, 79 | {-2,-1}, {-1,-1}, { 0,-1}, { 1,-1}, { 2,-1}, 80 | {-2,-2}, {-1,-2}, { 0,-2}, { 1,-2}, { 2,-2}, 81 | }; 82 | 83 | //! returns a random neighbor position for the specified pixel position; also guards against out-of-bounds values via image/border size check. 84 | static inline void getRandNeighborPosition_5x5(int& x_neighbor, int& y_neighbor, const int x_orig, const int y_orig, const int border, const cv::Size& imgsize) { 85 | int r = rand()%s_anNeighborPatternSize_5x5; 86 | x_neighbor = x_orig+s_anNeighborPattern_5x5[r][0]; 87 | y_neighbor = y_orig+s_anNeighborPattern_5x5[r][1]; 88 | if(x_neighbor=imgsize.width-border) 91 | x_neighbor = imgsize.width-border-1; 92 | if(y_neighbor=imgsize.height-border) 95 | y_neighbor = imgsize.height-border-1; 96 | } 97 | -------------------------------------------------------------------------------- /ViBe_LBSP.sdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP.sdf -------------------------------------------------------------------------------- /ViBe_LBSP.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ViBe_LBSP", "ViBe_LBSP\ViBe_LBSP.vcxproj", "{6EB585C8-250E-41BD-970C-5B76C84E1F0B}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Debug|x64 = Debug|x64 10 | Release|Win32 = Release|Win32 11 | Release|x64 = Release|x64 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {6EB585C8-250E-41BD-970C-5B76C84E1F0B}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {6EB585C8-250E-41BD-970C-5B76C84E1F0B}.Debug|Win32.Build.0 = Debug|Win32 16 | {6EB585C8-250E-41BD-970C-5B76C84E1F0B}.Debug|x64.ActiveCfg = Debug|x64 17 | {6EB585C8-250E-41BD-970C-5B76C84E1F0B}.Debug|x64.Build.0 = Debug|x64 18 | {6EB585C8-250E-41BD-970C-5B76C84E1F0B}.Release|Win32.ActiveCfg = Release|Win32 19 | {6EB585C8-250E-41BD-970C-5B76C84E1F0B}.Release|Win32.Build.0 = Release|Win32 20 | {6EB585C8-250E-41BD-970C-5B76C84E1F0B}.Release|x64.ActiveCfg = Release|x64 21 | {6EB585C8-250E-41BD-970C-5B76C84E1F0B}.Release|x64.Build.0 = Release|x64 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | EndGlobal 27 | -------------------------------------------------------------------------------- /ViBe_LBSP/Debug/BackgroundSubtractorLBSP.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP/Debug/BackgroundSubtractorLBSP.obj -------------------------------------------------------------------------------- /ViBe_LBSP/Debug/BackgroundSubtractorSuBSENSE.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP/Debug/BackgroundSubtractorSuBSENSE.obj -------------------------------------------------------------------------------- /ViBe_LBSP/Debug/CL.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP/Debug/CL.read.1.tlog -------------------------------------------------------------------------------- /ViBe_LBSP/Debug/CL.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP/Debug/CL.write.1.tlog -------------------------------------------------------------------------------- /ViBe_LBSP/Debug/LBSP.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP/Debug/LBSP.obj -------------------------------------------------------------------------------- /ViBe_LBSP/Debug/ViBe_LBSP.Build.CppClean.log: -------------------------------------------------------------------------------- 1 | C:\USERS\M\DESKTOP\VIBE_LBSP仅RGB\DEBUG\VIBE_LBSP.EXE 2 | C:\USERS\M\DESKTOP\VIBE_LBSP仅RGB\DEBUG\VIBE_LBSP.ILK 3 | C:\USERS\M\DESKTOP\VIBE_LBSP仅RGB\DEBUG\VIBE_LBSP.PDB 4 | C:\USERS\M\DESKTOP\VIBE_LBSP仅RGB\VIBE_LBSP\DEBUG\BACKGROUNDSUBTRACTORLBSP.OBJ 5 | C:\USERS\M\DESKTOP\VIBE_LBSP仅RGB\VIBE_LBSP\DEBUG\BACKGROUNDSUBTRACTORSUBSENSE.OBJ 6 | C:\USERS\M\DESKTOP\VIBE_LBSP仅RGB\VIBE_LBSP\DEBUG\BGFG_SEGM.OBJ 7 | C:\Users\m\Desktop\ViBe_LBSP仅RGB\ViBe_LBSP\Debug\cl.command.1.tlog 8 | C:\Users\m\Desktop\ViBe_LBSP仅RGB\ViBe_LBSP\Debug\CL.read.1.tlog 9 | C:\Users\m\Desktop\ViBe_LBSP仅RGB\ViBe_LBSP\Debug\CL.write.1.tlog 10 | C:\USERS\M\DESKTOP\VIBE_LBSP仅RGB\VIBE_LBSP\DEBUG\LBSP.OBJ 11 | C:\Users\m\Desktop\ViBe_LBSP仅RGB\ViBe_LBSP\Debug\link.command.1.tlog 12 | C:\Users\m\Desktop\ViBe_LBSP仅RGB\ViBe_LBSP\Debug\link.read.1.tlog 13 | C:\Users\m\Desktop\ViBe_LBSP仅RGB\ViBe_LBSP\Debug\link.write.1.tlog 14 | C:\Users\m\Desktop\ViBe_LBSP仅RGB\ViBe_LBSP\Debug\mt.command.1.tlog 15 | C:\Users\m\Desktop\ViBe_LBSP仅RGB\ViBe_LBSP\Debug\mt.read.1.tlog 16 | C:\Users\m\Desktop\ViBe_LBSP仅RGB\ViBe_LBSP\Debug\mt.read.2.tlog 17 | C:\Users\m\Desktop\ViBe_LBSP仅RGB\ViBe_LBSP\Debug\mt.write.1.tlog 18 | C:\Users\m\Desktop\ViBe_LBSP仅RGB\ViBe_LBSP\Debug\vc100.idb 19 | C:\USERS\M\DESKTOP\VIBE_LBSP仅RGB\VIBE_LBSP\DEBUG\VC100.PDB 20 | C:\USERS\M\DESKTOP\VIBE_LBSP仅RGB\VIBE_LBSP\DEBUG\VIBE_LBSP.EXE.INTERMEDIATE.MANIFEST 21 | C:\Users\m\Desktop\ViBe_LBSP仅RGB\ViBe_LBSP\Debug\ViBe_LBSP.write.1.tlog 22 | -------------------------------------------------------------------------------- /ViBe_LBSP/Debug/ViBe_LBSP.exe.intermediate.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /ViBe_LBSP/Debug/ViBe_LBSP.lastbuildstate: -------------------------------------------------------------------------------- 1 | #v4.0:v100:false 2 | Debug|Win32|C:\Users\m\Desktop\ViBe_LBSP仅RGB\| 3 | -------------------------------------------------------------------------------- /ViBe_LBSP/Debug/ViBe_LBSP.log: -------------------------------------------------------------------------------- 1 | 生成启动时间为 2016/4/13 20:56:26。 2 | 1>项目“C:\Users\m\Desktop\ViBe_LBSP仅RGB\ViBe_LBSP\ViBe_LBSP.vcxproj”在节点 2 上(build 个目标)。 3 | 1>InitializeBuildStatus: 4 | 正在创建“Debug\ViBe_LBSP.unsuccessfulbuild”,因为已指定“AlwaysCreate”。 5 | ClCompile: 6 | D:\Program Files\Microsoft Visual Studio 10.0\VC\bin\CL.exe /c /ZI /nologo /W3 /WX- /Od /Oy- /D _MBCS /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fo"Debug\\" /Fd"Debug\vc100.pdb" /Gd /TP /analyze- /errorReport:prompt ..\bgfg_segm.cpp 7 | bgfg_segm.cpp 8 | Link: 9 | D:\Program Files\Microsoft Visual Studio 10.0\VC\bin\link.exe /ERRORREPORT:PROMPT /OUT:"C:\Users\m\Desktop\ViBe_LBSP仅RGB\Debug\ViBe_LBSP.exe" /NOLOGO opencv_ml249d.lib opencv_calib3d249d.lib opencv_contrib249d.lib opencv_core249d.lib opencv_features2d249d.lib opencv_flann249d.lib opencv_gpu249d.lib opencv_highgui249d.lib opencv_imgproc249d.lib opencv_legacy249d.lib opencv_objdetect249d.lib opencv_ts249d.lib opencv_video249d.lib opencv_nonfree249d.lib opencv_ocl249d.lib opencv_photo249d.lib opencv_stitching249d.lib opencv_superres249d.lib opencv_videostab249d.lib opencv_objdetect249.lib opencv_ts249.lib opencv_video249.lib opencv_nonfree249.lib opencv_ocl249.lib opencv_photo249.lib opencv_stitching249.lib opencv_superres249.lib opencv_videostab249.lib opencv_calib3d249.lib opencv_contrib249.lib opencv_core249.lib opencv_features2d249.lib opencv_flann249.lib opencv_gpu249.lib opencv_highgui249.lib opencv_imgproc249.lib opencv_legacy249.lib opencv_ml249.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /ManifestFile:"Debug\ViBe_LBSP.exe.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"C:\Users\m\Desktop\ViBe_LBSP仅RGB\Debug\ViBe_LBSP.pdb" /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:\Users\m\Desktop\ViBe_LBSP仅RGB\Debug\ViBe_LBSP.lib" /MACHINE:X86 Debug\BackgroundSubtractorLBSP.obj 10 | Debug\BackgroundSubtractorSuBSENSE.obj 11 | Debug\bgfg_segm.obj 12 | Debug\LBSP.obj 13 | LINK : 没有找到 C:\Users\m\Desktop\ViBe_LBSP仅RGB\Debug\ViBe_LBSP.exe 或上一个增量链接没有生成它;正在执行完全链接 14 | ViBe_LBSP.vcxproj -> C:\Users\m\Desktop\ViBe_LBSP仅RGB\Debug\ViBe_LBSP.exe 15 | Manifest: 16 | C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\mt.exe /nologo /verbose /outputresource:"C:\Users\m\Desktop\ViBe_LBSP仅RGB\Debug\ViBe_LBSP.exe;#1" /manifest Debug\ViBe_LBSP.exe.intermediate.manifest 17 | FinalizeBuildStatus: 18 | 正在删除文件“Debug\ViBe_LBSP.unsuccessfulbuild”。 19 | 正在对“Debug\ViBe_LBSP.lastbuildstate”执行 Touch 任务。 20 | 1>已完成生成项目“C:\Users\m\Desktop\ViBe_LBSP仅RGB\ViBe_LBSP\ViBe_LBSP.vcxproj”(build 个目标)的操作。 21 | 22 | 生成成功。 23 | 24 | 已用时间 00:00:02.50 25 | -------------------------------------------------------------------------------- /ViBe_LBSP/Debug/ViBe_LBSP.vcxprojResolveAssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP/Debug/ViBe_LBSP.vcxprojResolveAssemblyReference.cache -------------------------------------------------------------------------------- /ViBe_LBSP/Debug/bgfg_segm.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP/Debug/bgfg_segm.obj -------------------------------------------------------------------------------- /ViBe_LBSP/Debug/cl.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP/Debug/cl.command.1.tlog -------------------------------------------------------------------------------- /ViBe_LBSP/Debug/link.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP/Debug/link.command.1.tlog -------------------------------------------------------------------------------- /ViBe_LBSP/Debug/link.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP/Debug/link.read.1.tlog -------------------------------------------------------------------------------- /ViBe_LBSP/Debug/link.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP/Debug/link.write.1.tlog -------------------------------------------------------------------------------- /ViBe_LBSP/Debug/mt.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP/Debug/mt.command.1.tlog -------------------------------------------------------------------------------- /ViBe_LBSP/Debug/mt.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP/Debug/mt.read.1.tlog -------------------------------------------------------------------------------- /ViBe_LBSP/Debug/mt.read.2.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP/Debug/mt.read.2.tlog -------------------------------------------------------------------------------- /ViBe_LBSP/Debug/mt.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP/Debug/mt.write.1.tlog -------------------------------------------------------------------------------- /ViBe_LBSP/Debug/vc100.idb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP/Debug/vc100.idb -------------------------------------------------------------------------------- /ViBe_LBSP/Debug/vc100.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP/Debug/vc100.pdb -------------------------------------------------------------------------------- /ViBe_LBSP/ViBe_LBSP.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {6EB585C8-250E-41BD-970C-5B76C84E1F0B} 23 | ViBe_LBSP 24 | 25 | 26 | 27 | Application 28 | true 29 | MultiByte 30 | 31 | 32 | Application 33 | true 34 | MultiByte 35 | 36 | 37 | Application 38 | false 39 | true 40 | MultiByte 41 | 42 | 43 | Application 44 | false 45 | true 46 | MultiByte 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | C:\Users\m\Desktop\ViBe_LBSP仅RGB;D:\opencv2.4.9\build\include;D:\opencv2.4.9\build\include\opencv;D:\opencv2.4.9\build\include\opencv2;$(IncludePath) 66 | 67 | 68 | D:\opencv2.4.11\build\include;D:\opencv2.4.11\build\include\opencv;D:\opencv2.4.11\build\include\opencv2;$(IncludePath) 69 | 70 | 71 | D:\opencv2.4.9\build\x86\vc10\lib;$(LibraryPath) 72 | 73 | 74 | D:\opencv2.4.11\build\x64\vc10\lib;$(LibraryPath) 75 | 76 | 77 | 78 | Level3 79 | Disabled 80 | 81 | 82 | true 83 | opencv_ml249d.lib;opencv_calib3d249d.lib;opencv_contrib249d.lib;opencv_core249d.lib;opencv_features2d249d.lib;opencv_flann249d.lib;opencv_gpu249d.lib;opencv_highgui249d.lib;opencv_imgproc249d.lib;opencv_legacy249d.lib;opencv_objdetect249d.lib;opencv_ts249d.lib;opencv_video249d.lib;opencv_nonfree249d.lib;opencv_ocl249d.lib;opencv_photo249d.lib;opencv_stitching249d.lib;opencv_superres249d.lib;opencv_videostab249d.lib;opencv_objdetect249.lib;opencv_ts249.lib;opencv_video249.lib;opencv_nonfree249.lib;opencv_ocl249.lib;opencv_photo249.lib;opencv_stitching249.lib;opencv_superres249.lib;opencv_videostab249.lib;opencv_calib3d249.lib;opencv_contrib249.lib;opencv_core249.lib;opencv_features2d249.lib;opencv_flann249.lib;opencv_gpu249.lib;opencv_highgui249.lib;opencv_imgproc249.lib;opencv_legacy249.lib;opencv_ml249.lib;%(AdditionalDependencies) 84 | 85 | 86 | 87 | 88 | Level3 89 | Disabled 90 | 91 | 92 | true 93 | opencv_ml2411d.lib;opencv_calib3d2411d.lib;opencv_contrib2411d.lib;opencv_core2411d.lib;opencv_features2d2411d.lib;opencv_flann2411d.lib;opencv_gpu2411d.lib;opencv_highgui2411d.lib;opencv_imgproc2411d.lib;opencv_legacy2411d.lib;opencv_objdetect2411d.lib;opencv_ts2411d.lib;opencv_video2411d.lib;opencv_nonfree2411d.lib;opencv_ocl2411d.lib;opencv_photo2411d.lib;opencv_stitching2411d.lib;opencv_superres2411d.lib;opencv_videostab2411d.lib;opencv_objdetect2411.lib;opencv_ts2411.lib;opencv_video2411.lib;opencv_nonfree2411.lib;opencv_ocl2411.lib;opencv_photo2411.lib;opencv_stitching2411.lib;opencv_superres2411.lib;opencv_videostab2411.lib;opencv_calib3d2411.lib;opencv_contrib2411.lib;opencv_core2411.lib;opencv_features2d2411.lib;opencv_flann2411.lib;opencv_gpu2411.lib;opencv_highgui2411.lib;opencv_imgproc2411.lib;opencv_legacy2411.lib;opencv_ml2411.lib;%(AdditionalDependencies) 94 | 95 | 96 | 97 | 98 | Level3 99 | MaxSpeed 100 | true 101 | true 102 | 103 | 104 | true 105 | true 106 | true 107 | 108 | 109 | 110 | 111 | Level3 112 | MaxSpeed 113 | true 114 | true 115 | 116 | 117 | true 118 | true 119 | true 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | -------------------------------------------------------------------------------- /ViBe_LBSP/ViBe_LBSP.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 头文件 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 头文件 29 | 30 | 31 | 头文件 32 | 33 | 34 | 35 | 36 | 源文件 37 | 38 | 39 | 源文件 40 | 41 | 42 | 源文件 43 | 44 | 45 | 源文件 46 | 47 | 48 | -------------------------------------------------------------------------------- /ViBe_LBSP/ViBe_LBSP.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | WindowsLocalDebugger 7 | 8 | -------------------------------------------------------------------------------- /ViBe_LBSP/readfolder.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP/readfolder.cpp -------------------------------------------------------------------------------- /ViBe_LBSP/readfolder.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP/readfolder.h -------------------------------------------------------------------------------- /ViBe_LBSP/test_SuBSENSE.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP/test_SuBSENSE.cpp -------------------------------------------------------------------------------- /ViBe_LBSP/x64/Debug/BackgroundSubtractorLBSP.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP/x64/Debug/BackgroundSubtractorLBSP.obj -------------------------------------------------------------------------------- /ViBe_LBSP/x64/Debug/BackgroundSubtractorSuBSENSE.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP/x64/Debug/BackgroundSubtractorSuBSENSE.obj -------------------------------------------------------------------------------- /ViBe_LBSP/x64/Debug/CL.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP/x64/Debug/CL.read.1.tlog -------------------------------------------------------------------------------- /ViBe_LBSP/x64/Debug/CL.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP/x64/Debug/CL.write.1.tlog -------------------------------------------------------------------------------- /ViBe_LBSP/x64/Debug/LBSP.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP/x64/Debug/LBSP.obj -------------------------------------------------------------------------------- /ViBe_LBSP/x64/Debug/ViBe_LBSP.exe.intermediate.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /ViBe_LBSP/x64/Debug/ViBe_LBSP.lastbuildstate: -------------------------------------------------------------------------------- 1 | #v4.0:v100:false 2 | Debug|x64|C:\Users\m\Desktop\新\22三\ViBe_LBSP仅RGB\| 3 | -------------------------------------------------------------------------------- /ViBe_LBSP/x64/Debug/ViBe_LBSP.log: -------------------------------------------------------------------------------- 1 | 生成启动时间为 2016/6/21 12:21:56。 2 | 1>项目“C:\Users\m\Desktop\新\22三\ViBe_LBSP仅RGB\ViBe_LBSP\ViBe_LBSP.vcxproj”在节点 2 上(build 个目标)。 3 | 1>InitializeBuildStatus: 4 | 正在创建“x64\Debug\ViBe_LBSP.unsuccessfulbuild”,因为已指定“AlwaysCreate”。 5 | ClCompile: 6 | D:\Visual Studio 2010\VC\bin\x86_amd64\CL.exe /c /Zi /nologo /W3 /WX- /Od /D _MBCS /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fo"x64\Debug\\" /Fd"x64\Debug\vc100.pdb" /Gd /TP /errorReport:prompt ..\bgfg_segm.cpp 7 | bgfg_segm.cpp 8 | Link: 9 | D:\Visual Studio 2010\VC\bin\x86_amd64\link.exe /ERRORREPORT:PROMPT /OUT:"C:\Users\m\Desktop\新\22三\ViBe_LBSP仅RGB\x64\Debug\ViBe_LBSP.exe" /NOLOGO opencv_ml2411d.lib opencv_calib3d2411d.lib opencv_contrib2411d.lib opencv_core2411d.lib opencv_features2d2411d.lib opencv_flann2411d.lib opencv_gpu2411d.lib opencv_highgui2411d.lib opencv_imgproc2411d.lib opencv_legacy2411d.lib opencv_objdetect2411d.lib opencv_ts2411d.lib opencv_video2411d.lib opencv_nonfree2411d.lib opencv_ocl2411d.lib opencv_photo2411d.lib opencv_stitching2411d.lib opencv_superres2411d.lib opencv_videostab2411d.lib opencv_objdetect2411.lib opencv_ts2411.lib opencv_video2411.lib opencv_nonfree2411.lib opencv_ocl2411.lib opencv_photo2411.lib opencv_stitching2411.lib opencv_superres2411.lib opencv_videostab2411.lib opencv_calib3d2411.lib opencv_contrib2411.lib opencv_core2411.lib opencv_features2d2411.lib opencv_flann2411.lib opencv_gpu2411.lib opencv_highgui2411.lib opencv_imgproc2411.lib opencv_legacy2411.lib opencv_ml2411.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /ManifestFile:"x64\Debug\ViBe_LBSP.exe.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"C:\Users\m\Desktop\新\22三\ViBe_LBSP仅RGB\x64\Debug\ViBe_LBSP.pdb" /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:\Users\m\Desktop\新\22三\ViBe_LBSP仅RGB\x64\Debug\ViBe_LBSP.lib" /MACHINE:X64 x64\Debug\BackgroundSubtractorLBSP.obj 10 | x64\Debug\BackgroundSubtractorSuBSENSE.obj 11 | x64\Debug\bgfg_segm.obj 12 | x64\Debug\LBSP.obj 13 | LINK : 没有找到 C:\Users\m\Desktop\新\22三\ViBe_LBSP仅RGB\x64\Debug\ViBe_LBSP.exe 或上一个增量链接没有生成它;正在执行完全链接 14 | ViBe_LBSP.vcxproj -> C:\Users\m\Desktop\新\22三\ViBe_LBSP仅RGB\x64\Debug\ViBe_LBSP.exe 15 | Manifest: 16 | C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\mt.exe /nologo /verbose /outputresource:"C:\Users\m\Desktop\新\22三\ViBe_LBSP仅RGB\x64\Debug\ViBe_LBSP.exe;#1" /manifest x64\Debug\ViBe_LBSP.exe.intermediate.manifest 17 | FinalizeBuildStatus: 18 | 正在删除文件“x64\Debug\ViBe_LBSP.unsuccessfulbuild”。 19 | 正在对“x64\Debug\ViBe_LBSP.lastbuildstate”执行 Touch 任务。 20 | 1>已完成生成项目“C:\Users\m\Desktop\新\22三\ViBe_LBSP仅RGB\ViBe_LBSP\ViBe_LBSP.vcxproj”(build 个目标)的操作。 21 | 22 | 生成成功。 23 | 24 | 已用时间 00:00:01.65 25 | -------------------------------------------------------------------------------- /ViBe_LBSP/x64/Debug/ViBe_LBSP.vcxprojResolveAssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP/x64/Debug/ViBe_LBSP.vcxprojResolveAssemblyReference.cache -------------------------------------------------------------------------------- /ViBe_LBSP/x64/Debug/bgfg_segm.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP/x64/Debug/bgfg_segm.obj -------------------------------------------------------------------------------- /ViBe_LBSP/x64/Debug/cl.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP/x64/Debug/cl.command.1.tlog -------------------------------------------------------------------------------- /ViBe_LBSP/x64/Debug/link.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP/x64/Debug/link.command.1.tlog -------------------------------------------------------------------------------- /ViBe_LBSP/x64/Debug/link.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP/x64/Debug/link.read.1.tlog -------------------------------------------------------------------------------- /ViBe_LBSP/x64/Debug/link.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP/x64/Debug/link.write.1.tlog -------------------------------------------------------------------------------- /ViBe_LBSP/x64/Debug/mt.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP/x64/Debug/mt.command.1.tlog -------------------------------------------------------------------------------- /ViBe_LBSP/x64/Debug/mt.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP/x64/Debug/mt.read.1.tlog -------------------------------------------------------------------------------- /ViBe_LBSP/x64/Debug/mt.read.2.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP/x64/Debug/mt.read.2.tlog -------------------------------------------------------------------------------- /ViBe_LBSP/x64/Debug/mt.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP/x64/Debug/mt.write.1.tlog -------------------------------------------------------------------------------- /ViBe_LBSP/x64/Debug/vc100.idb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP/x64/Debug/vc100.idb -------------------------------------------------------------------------------- /ViBe_LBSP/x64/Debug/vc100.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ViBe_LBSP/x64/Debug/vc100.pdb -------------------------------------------------------------------------------- /bgfg_segm.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/bgfg_segm.cpp -------------------------------------------------------------------------------- /ipch/vibe_lbsp-b01e80ba/vibe_lbsp-6c103fc0.ipch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/ipch/vibe_lbsp-b01e80ba/vibe_lbsp-6c103fc0.ipch -------------------------------------------------------------------------------- /readfolder.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/readfolder.cpp -------------------------------------------------------------------------------- /readfolder.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/readfolder.h -------------------------------------------------------------------------------- /x64/Debug/ViBe_LBSP.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/x64/Debug/ViBe_LBSP.exe -------------------------------------------------------------------------------- /x64/Debug/ViBe_LBSP.ilk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/x64/Debug/ViBe_LBSP.ilk -------------------------------------------------------------------------------- /x64/Debug/ViBe_LBSP.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimeng100/WeSamBE/2a3f469a08eee24283a1d611ad34ed49580372e6/x64/Debug/ViBe_LBSP.pdb --------------------------------------------------------------------------------