背景建模技术(六):帧处理(FrameProcessor)模块

本文深入探讨了BgsLibrary中的帧处理(FrameProcessor)模块,该模块负责对视频每一帧进行处理,是实际应用背景建模算法的关键接口。通过源码分析和流程框架图,读者可以理解其工作原理。
摘要由CSDN通过智能技术生成

前面几篇文章简单介绍了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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值