前面几篇文章简单介绍了BgsLibrary的入口函数、视频分析和视频捕获模块,本文将简单介绍帧处理模块,即对每一帧进行处理的函数,也就是真正调用背景建模算法的接口处。
下面贴出源码供大家分析:
#include "FrameProcessor.h"
#include <iomanip>
namespace bgslibrary
{
FrameProcessor::FrameProcessor() : firstTime(true), frameNumber(0), duration(0), tictoc(""), frameToStop(0)
{
std::cout << "FrameProcessor()" << std::endl;
loadConfig();
saveConfig();
}
FrameProcessor::~FrameProcessor()
{
std::cout << "~FrameProcessor()" << std::endl;
}
void FrameProcessor::init()
{
if (enablePreProcessor)
preProcessor = new PreProcessor;
if (enableFrameDifferenceBGS)
frameDifference = new FrameDifferenceBGS;
if (enableStaticFrameDifferenceBGS)
staticFrameDifference = new StaticFrameDifferenceBGS;
if (enableWeightedMovingMeanBGS)
weightedMovingMean = new WeightedMovingMeanBGS;
if (enableWeightedMovingVarianceBGS)
weightedMovingVariance = new WeightedMovingVarianceBGS;
if (enableMixtureOfGaussianV1BGS)
mixtureOfGaussianV1BGS = new MixtureOfGaussianV1BGS;
if (enableMixtureOfGaussianV2BGS)
mixtureOfGaussianV2BGS = new MixtureOfGaussianV2BGS;
if (enableAdaptiveBackgroundLearning)
adaptiveBackgroundLearning = new AdaptiveBackgroundLearning;
#if CV_MAJOR_VERSION >= 2 && CV_MINOR_VERSION >= 4 && CV_SUBMINOR_VERSION >= 3
if (enableGMG)
gmg = new GMG;
#endif
if (enableDPAdaptiveMedianBGS)
adaptiveMedian = new DPAdaptiveMedianBGS;
if (enableDPGrimsonGMMBGS)
grimsonGMM = new DPGrimsonGMMBGS;
if (enableDPZivkovicAGMMBGS)
zivkovicAGMM = new DPZivkovicAGMMBGS;
if (enableDPMeanBGS)
temporalMean = new DPMeanBGS;
if (enableDPWrenGABGS)
wrenGA = new DPWrenGABGS;
if (enableDPPratiMediodBGS)
pratiMediod = new DPPratiMediodBGS;
if (enableDPEigenbackgroundBGS)
eigenBackground = new DPEigenbackgroundBGS;
if (enableDPTextureBGS)
textureBGS = new DPTextureBGS;
if (enableT2FGMM_UM)
type2FuzzyGMM_UM = new T2FGMM_UM;
if (enableT2FGMM_UV)
type2FuzzyGMM_UV = new T2FGMM_UV;
if (enableT2FMRF_UM)
type2FuzzyMRF_UM = new T2FMRF_UM;
if (enableT2FMRF_UV)
type2FuzzyMRF_UV = new T2FMRF_UV;
if (enableFuzzySugenoIntegral)
fuzzySugenoIntegral = new FuzzySugenoIntegral;
if (enableFuzzyChoquetIntegral)
fuzzyChoquetIntegral = new FuzzyChoquetIntegral;
if (enableLBSimpleGaussian)
lbSimpleGaussian = new LBSimpleGaussian;
if (enableLBFuzzyGaussian)
lbFuzzyGaussian = new LBFuzzyGaussian;
if (enableLBMixtureOfGaussians)
lbMixtureOfGaussians = new LBMixtureOfGaussians;
if (enableLBAdaptiveSOM)
lbAdaptiveSOM = new LBAdaptiveSOM;
if (enableLBFuzzyAdaptiveSOM)
lbFuzzyAdaptiveSOM = new LBFuzzyAdaptiveSOM;
if (enableLbpMrf)
lbpMrf = new LbpMrf;
if(enableMultiLayerBGS)
multiLayerBGS = new MultiLayerBGS;
//if(enablePBAS)
// pixelBasedAdaptiveSegmenter = new PixelBasedAdaptiveSegmenter;
if (enableVuMeter)
vuMeter = new VuMeter;
if (enableKDE)
kde = new KDE;
if (enableIMBS)
imbs = new IndependentMultimodalBGS;
if (enableMultiCueBGS)
mcbgs = new SJN_MultiCueBGS;
if (enableSigmaDeltaBGS)
sdbgs = new SigmaDeltaBGS;
if (enableSuBSENSEBGS)
ssbgs = new SuBSENSEBGS;
if (enableLOBSTERBGS)
lobgs = new LOBSTERBGS;
if (enableForegroundMaskAnalysis)
foregroundMaskAnalysis = new ForegroundMaskAnalysis;
}
void FrameProcessor::process(std::string name, IBGS *bgs, const cv::Mat &img_input, cv::Mat &img_bgs)
{
if (tictoc == name)
tic(name);
cv::Mat img_bkgmodel;
bgs->process(img_input, img_bgs, img_bkgmodel);//直接调用各种背景建模算法
if (tictoc == name)
toc();
}
void FrameProcessor::process(const cv::Mat &img_input)
{
frameNumber++;
///enablePreProcessor///
if (enablePreProcessor)
preProcessor->process(img_input, img_prep);
/******************************************************************/
/*根据config文件使能各种背景建模算法,可以同时使用多种背景建模算法*/
/******************************************************************/
///1:Frame Difference
if (enableFrameDifferenceBGS)
process("FrameDifferenceBGS", frameDifference, img_prep, img_fr