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


    前面几篇文章简单介绍了BgsLibrary的入口函数视频分析视频捕获模块,本文将简单介绍帧处理模块,即对每一帧进行处理的函数,也就是真正调用背景建模算法的接口处。

    下面贴出源码供大家分析:

    1. #include "FrameProcessor.h"  
    2. #include <iomanip>  
    3.   
    4. namespace bgslibrary  
    5. {  
    6.   FrameProcessor::FrameProcessor() : firstTime(true), frameNumber(0), duration(0), tictoc(""), frameToStop(0)  
    7.   {  
    8.     std::cout << "FrameProcessor()" << std::endl;  
    9.   
    10.     loadConfig();  
    11.     saveConfig();  
    12.   }  
    13.   
    14.   FrameProcessor::~FrameProcessor()  
    15.   {  
    16.     std::cout << "~FrameProcessor()" << std::endl;  
    17.   }  
    18.   
    19.   void FrameProcessor::init()  
    20.   {  
    21.     if (enablePreProcessor)  
    22.       preProcessor = new PreProcessor;  
    23.   
    24.     if (enableFrameDifferenceBGS)  
    25.       frameDifference = new FrameDifferenceBGS;  
    26.   
    27.     if (enableStaticFrameDifferenceBGS)  
    28.       staticFrameDifference = new StaticFrameDifferenceBGS;  
    29.   
    30.     if (enableWeightedMovingMeanBGS)  
    31.       weightedMovingMean = new WeightedMovingMeanBGS;  
    32.   
    33.     if (enableWeightedMovingVarianceBGS)  
    34.       weightedMovingVariance = new WeightedMovingVarianceBGS;  
    35.   
    36.     if (enableMixtureOfGaussianV1BGS)  
    37.       mixtureOfGaussianV1BGS = new MixtureOfGaussianV1BGS;  
    38.   
    39.     if (enableMixtureOfGaussianV2BGS)  
    40.       mixtureOfGaussianV2BGS = new MixtureOfGaussianV2BGS;  
    41.   
    42.     if (enableAdaptiveBackgroundLearning)  
    43.       adaptiveBackgroundLearning = new AdaptiveBackgroundLearning;  
    44.   
    45. #if CV_MAJOR_VERSION >= 2 && CV_MINOR_VERSION >= 4 && CV_SUBMINOR_VERSION >= 3  
    46.     if (enableGMG)  
    47.       gmg = new GMG;  
    48. #endif  
    49.   
    50.     if (enableDPAdaptiveMedianBGS)  
    51.       adaptiveMedian = new DPAdaptiveMedianBGS;  
    52.   
    53.     if (enableDPGrimsonGMMBGS)  
    54.       grimsonGMM = new DPGrimsonGMMBGS;  
    55.   
    56.     if (enableDPZivkovicAGMMBGS)  
    57.       zivkovicAGMM = new DPZivkovicAGMMBGS;  
    58.   
    59.     if (enableDPMeanBGS)  
    60.       temporalMean = new DPMeanBGS;  
    61.   
    62.     if (enableDPWrenGABGS)  
    63.       wrenGA = new DPWrenGABGS;  
    64.   
    65.     if (enableDPPratiMediodBGS)  
    66.       pratiMediod = new DPPratiMediodBGS;  
    67.   
    68.     if (enableDPEigenbackgroundBGS)  
    69.       eigenBackground = new DPEigenbackgroundBGS;  
    70.   
    71.     if (enableDPTextureBGS)  
    72.       textureBGS = new DPTextureBGS;  
    73.   
    74.     if (enableT2FGMM_UM)  
    75.       type2FuzzyGMM_UM = new T2FGMM_UM;  
    76.   
    77.     if (enableT2FGMM_UV)  
    78.       type2FuzzyGMM_UV = new T2FGMM_UV;  
    79.   
    80.     if (enableT2FMRF_UM)  
    81.       type2FuzzyMRF_UM = new T2FMRF_UM;  
    82.   
    83.     if (enableT2FMRF_UV)  
    84.       type2FuzzyMRF_UV = new T2FMRF_UV;  
    85.   
    86.     if (enableFuzzySugenoIntegral)  
    87.       fuzzySugenoIntegral = new FuzzySugenoIntegral;  
    88.   
    89.     if (enableFuzzyChoquetIntegral)  
    90.       fuzzyChoquetIntegral = new FuzzyChoquetIntegral;  
    91.   
    92.     if (enableLBSimpleGaussian)  
    93.       lbSimpleGaussian = new LBSimpleGaussian;  
    94.   
    95.     if (enableLBFuzzyGaussian)  
    96.       lbFuzzyGaussian = new LBFuzzyGaussian;  
    97.   
    98.     if (enableLBMixtureOfGaussians)  
    99.       lbMixtureOfGaussians = new LBMixtureOfGaussians;  
    100.   
    101.     if (enableLBAdaptiveSOM)  
    102.       lbAdaptiveSOM = new LBAdaptiveSOM;  
    103.   
    104.     if (enableLBFuzzyAdaptiveSOM)  
    105.       lbFuzzyAdaptiveSOM = new LBFuzzyAdaptiveSOM;  
    106.   
    107.     if (enableLbpMrf)  
    108.       lbpMrf = new LbpMrf;  
    109.   
    110.     if(enableMultiLayerBGS)  
    111.       multiLayerBGS = new MultiLayerBGS;  
    112.   
    113.     //if(enablePBAS)  
    114.     //  pixelBasedAdaptiveSegmenter = new PixelBasedAdaptiveSegmenter;  
    115.   
    116.     if (enableVuMeter)  
    117.       vuMeter = new VuMeter;  
    118.   
    119.     if (enableKDE)  
    120.       kde = new KDE;  
    121.   
    122.     if (enableIMBS)  
    123.       imbs = new IndependentMultimodalBGS;  
    124.   
    125.     if (enableMultiCueBGS)  
    126.       mcbgs = new SJN_MultiCueBGS;  
    127.   
    128.     if (enableSigmaDeltaBGS)  
    129.       sdbgs = new SigmaDeltaBGS;  
    130.   
    131.     if (enableSuBSENSEBGS)  
    132.       ssbgs = new SuBSENSEBGS;  
    133.   
    134.     if (enableLOBSTERBGS)  
    135.       lobgs = new LOBSTERBGS;  
    136.   
    137.     if (enableForegroundMaskAnalysis)  
    138.       foregroundMaskAnalysis = new ForegroundMaskAnalysis;  
    139.   }  
    140.   
    141.   void FrameProcessor::process(std::string name, IBGS *bgs, const cv::Mat &img_input, cv::Mat &img_bgs)  
    142.   {  
    143.     if (tictoc == name)  
    144.       tic(name);  
    145.   
    146.     cv::Mat img_bkgmodel;  
    147.     bgs->process(img_input, img_bgs, img_bkgmodel);//直接调用各种背景建模算法  
    148.   
    149.     if (tictoc == name)  
    150.       toc();  
    151.   }  
    152.   
    153.   void FrameProcessor::process(const cv::Mat &img_input)  
    154.   {  
    155.     frameNumber++;  
    156.   
    157.     ///enablePreProcessor///  
    158.     if (enablePreProcessor)  
    159.       preProcessor->process(img_input, img_prep);  
    160.       
    161.     /******************************************************************/  
    162.     /*根据config文件使能各种背景建模算法,可以同时使用多种背景建模算法*/  
    163.     /******************************************************************/  
    164.       
    165.     ///1:Frame Difference  
    166.     if (enableFrameDifferenceBGS)  
    167.       process("FrameDifferenceBGS", frameDifference, img_prep, img_framediff);  
    168.       
    169.     ///2:Static Frame Difference  
    170.     if (enableStaticFrameDifferenceBGS)  
    171.       process("StaticFrameDifferenceBGS", staticFrameDifference, img_prep, img_staticfdiff);  
    172.       
    173.     ///3:Weighted Moving Mean  
    174.     if (enableWeightedMovingMeanBGS)  
    175.       process("WeightedMovingMeanBGS", weightedMovingMean, img_prep, img_wmovmean);  
    176.       
    177.     ///4:Weighted Moving Variance  
    178.     if (enableWeightedMovingVarianceBGS)  
    179.       process("WeightedMovingVarianceBGS", weightedMovingVariance, img_prep, img_movvar);  
    180.       
    181.     ///5:Gaussian Mixture Model  
    182.     if (enableMixtureOfGaussianV1BGS)  
    183.       process("MixtureOfGaussianV1BGS", mixtureOfGaussianV1BGS, img_prep, img_mog1);  
    184.       
    185.     ///6:Gaussian Mixture Model  
    186.     if (enableMixtureOfGaussianV2BGS)  
    187.       process("MixtureOfGaussianV2BGS", mixtureOfGaussianV2BGS, img_prep, img_mog2);  
    188.       
    189.     ///7:Adaptive Background Learning  
    190.     if (enableAdaptiveBackgroundLearning)  
    191.       process("AdaptiveBackgroundLearning", adaptiveBackgroundLearning, img_prep, img_bkgl_fgmask);  
    192.       
    193.     ///8:GMG  
    194. #if CV_MAJOR_VERSION >= 2 && CV_MINOR_VERSION >= 4 && CV_SUBMINOR_VERSION >= 3  
    195.     if (enableGMG)  
    196.       process("GMG", gmg, img_prep, img_gmg);  
    197. #endif  
    198.       
    199.     ///9:Adaptive Median  
    200.     if (enableDPAdaptiveMedianBGS)  
    201.       process("DPAdaptiveMedianBGS", adaptiveMedian, img_prep, img_adpmed);  
    202.       
    203.     ///10:Gaussian Mixture Model  
    204.     if (enableDPGrimsonGMMBGS)  
    205.       process("DPGrimsonGMMBGS", grimsonGMM, img_prep, img_grigmm);  
    206.       
    207.     ///11:Gaussian Mixture Model  
    208.     if (enableDPZivkovicAGMMBGS)  
    209.       process("DPZivkovicAGMMBGS", zivkovicAGMM, img_prep, img_zivgmm);  
    210.       
    211.     ///12:Temporal Mean  
    212.     if (enableDPMeanBGS)  
    213.       process("DPMeanBGS", temporalMean, img_prep, img_tmpmean);  
    214.       
    215.     ///13:Gaussian Average  
    216.     if (enableDPWrenGABGS)  
    217.       process("DPWrenGABGS", wrenGA, img_prep, img_wrenga);  
    218.       
    219.     ///14:Temporal Median  
    220.     if (enableDPPratiMediodBGS)  
    221.       process("DPPratiMediodBGS", pratiMediod, img_prep, img_pramed);  
    222.       
    223.     ///15:Eigen background / SL-PCA  
    224.     if (enableDPEigenbackgroundBGS)  
    225.       process("DPEigenbackgroundBGS", eigenBackground, img_prep, img_eigbkg);  
    226.       
    227.     ///16:Texture BGS  
    228.     if (enableDPTextureBGS)  
    229.       process("DPTextureBGS", textureBGS, img_prep, img_texbgs);  
    230.       
    231.     ///17:Type-2 Fuzzy GMM-UM  
    232.     if (enableT2FGMM_UM)  
    233.       process("T2FGMM_UM", type2FuzzyGMM_UM, img_prep, img_t2fgmm_um);  
    234.       
    235.     ///18:Type-2 Fuzzy GMM-UV  
    236.     if (enableT2FGMM_UV)  
    237.       process("T2FGMM_UV", type2FuzzyGMM_UV, img_prep, img_t2fgmm_uv);  
    238.       
    239.     ///19:Type-2 Fuzzy GMM-UM with MRF  
    240.     if (enableT2FMRF_UM)  
    241.       process("T2FMRF_UM", type2FuzzyMRF_UM, img_prep, img_t2fmrf_um);  
    242.       
    243.     ///20:Type-2 Fuzzy GMM-UV with MRF  
    244.     if (enableT2FMRF_UV)  
    245.       process("T2FMRF_UV", type2FuzzyMRF_UV, img_prep, img_t2fmrf_uv);  
    246.       
    247.     ///21:Fuzzy Sugeno Integral  
    248.     if (enableFuzzySugenoIntegral)  
    249.       process("FuzzySugenoIntegral", fuzzySugenoIntegral, img_prep, img_fsi);  
    250.       
    251.     ///22:Fuzzy Choquet Integral  
    252.     if (enableFuzzyChoquetIntegral)  
    253.       process("FuzzyChoquetIntegral", fuzzyChoquetIntegral, img_prep, img_fci);  
    254.       
    255.     ///23:Simple Gaussian  
    256.     if (enableLBSimpleGaussian)  
    257.       process("LBSimpleGaussian", lbSimpleGaussian, img_prep, img_lb_sg);  
    258.       
    259.     ///24:Fuzzy Gaussian of Laurence Bender  
    260.     if (enableLBFuzzyGaussian)  
    261.       process("LBFuzzyGaussian", lbFuzzyGaussian, img_prep, img_lb_fg);  
    262.       
    263.     ///25:Gaussian Mixture Model  
    264.     if (enableLBMixtureOfGaussians)  
    265.       process("LBMixtureOfGaussians", lbMixtureOfGaussians, img_prep, img_lb_mog);  
    266.       
    267.     ///26:Adaptive SOM  
    268.     if (enableLBAdaptiveSOM)  
    269.       process("LBAdaptiveSOM", lbAdaptiveSOM, img_prep, img_lb_som);  
    270.       
    271.     ///27:Fuzzy Adaptive SOM  
    272.     if (enableLBFuzzyAdaptiveSOM)  
    273.       process("LBFuzzyAdaptiveSOM", lbFuzzyAdaptiveSOM, img_prep, img_lb_fsom);  
    274.       
    275.     ///28:LbpMrf  
    276.     if (enableLbpMrf)  
    277.       process("LbpMrf", lbpMrf, img_prep, img_lbp_mrf);  
    278.       
    279.     ///29:Multi-Layer BGS  
    280.     if(enableMultiLayerBGS)  
    281.     {  
    282.       multiLayerBGS->setStatus(MultiLayerBGS::MLBGS_LEARN);  
    283.       //multiLayerBGS->setStatus(MultiLayerBGS::MLBGS_DETECT);  
    284.       process("MultiLayerBGS", multiLayerBGS, img_prep, img_mlbgs);  
    285.     }  
    286.       
    287.     ///30:Pixel-Based Adaptive Segmenter  
    288.     //if(enablePBAS)  
    289.     //  process("PBAS", pixelBasedAdaptiveSegmenter, img_prep, img_pt_pbas);  
    290.       
    291.     ///31:VuMeter  
    292.     if (enableVuMeter)  
    293.       process("VuMeter", vuMeter, img_prep, img_vumeter);  
    294.       
    295.     ///32:Kernel Density Estimation  
    296.     if (enableKDE)  
    297.       process("KDE", kde, img_prep, img_kde);  
    298.       
    299.     ///33:Independent Multimodal BGS  
    300.     if (enableIMBS)  
    301.       process("IMBS", imbs, img_prep, img_imbs);  
    302.       
    303.     ///34:MultiCue BGS  
    304.     if (enableMultiCueBGS)  
    305.       process("MultiCueBGS", mcbgs, img_prep, img_mcbgs);  
    306.       
    307.     ///35:Sigma-Delta  
    308.     if (enableSigmaDeltaBGS)  
    309.       process("SigmaDeltaBGS", sdbgs, img_prep, img_sdbgs);  
    310.       
    311.     ///36:SuBSENSE  
    312.     if (enableSuBSENSEBGS)  
    313.       process("SuBSENSEBGS", ssbgs, img_prep, img_ssbgs);  
    314.       
    315.     ///37:LOBSTER  
    316.     if (enableLOBSTERBGS)  
    317.       process("LOBSTERBGS", lobgs, img_prep, img_lobgs);  
    318.       
    319.     ///enableForegroundMaskAnalysis///  
    320.     if (enableForegroundMaskAnalysis)  
    321.     {  
    322.       foregroundMaskAnalysis->stopAt = frameToStop;  
    323.       foregroundMaskAnalysis->img_ref_path = imgref;  
    324.   
    325.       foregroundMaskAnalysis->process(frameNumber, "FrameDifferenceBGS", img_framediff);  
    326.       foregroundMaskAnalysis->process(frameNumber, "StaticFrameDifferenceBGS", img_staticfdiff);  
    327.       foregroundMaskAnalysis->process(frameNumber, "WeightedMovingMeanBGS", img_wmovmean);  
    328.       foregroundMaskAnalysis->process(frameNumber, "WeightedMovingVarianceBGS", img_movvar);  
    329.       foregroundMaskAnalysis->process(frameNumber, "MixtureOfGaussianV1BGS", img_mog1);  
    330.       foregroundMaskAnalysis->process(frameNumber, "MixtureOfGaussianV2BGS", img_mog2);  
    331.       foregroundMaskAnalysis->process(frameNumber, "AdaptiveBackgroundLearning", img_bkgl_fgmask);  
    332. #if CV_MAJOR_VERSION >= 2 && CV_MINOR_VERSION >= 4 && CV_SUBMINOR_VERSION >= 3  
    333.       foregroundMaskAnalysis->process(frameNumber, "GMG", img_gmg);  
    334. #endif  
    335.       foregroundMaskAnalysis->process(frameNumber, "DPAdaptiveMedianBGS", img_adpmed);  
    336.       foregroundMaskAnalysis->process(frameNumber, "DPGrimsonGMMBGS", img_grigmm);  
    337.       foregroundMaskAnalysis->process(frameNumber, "DPZivkovicAGMMBGS", img_zivgmm);  
    338.       foregroundMaskAnalysis->process(frameNumber, "DPMeanBGS", img_tmpmean);  
    339.       foregroundMaskAnalysis->process(frameNumber, "DPWrenGABGS", img_wrenga);  
    340.       foregroundMaskAnalysis->process(frameNumber, "DPPratiMediodBGS", img_pramed);  
    341.       foregroundMaskAnalysis->process(frameNumber, "DPEigenbackgroundBGS", img_eigbkg);  
    342.       foregroundMaskAnalysis->process(frameNumber, "DPTextureBGS", img_texbgs);  
    343.       foregroundMaskAnalysis->process(frameNumber, "T2FGMM_UM", img_t2fgmm_um);  
    344.       foregroundMaskAnalysis->process(frameNumber, "T2FGMM_UV", img_t2fgmm_uv);  
    345.       foregroundMaskAnalysis->process(frameNumber, "T2FMRF_UM", img_t2fmrf_um);  
    346.       foregroundMaskAnalysis->process(frameNumber, "T2FMRF_UV", img_t2fmrf_uv);  
    347.       foregroundMaskAnalysis->process(frameNumber, "FuzzySugenoIntegral", img_fsi);  
    348.       foregroundMaskAnalysis->process(frameNumber, "FuzzyChoquetIntegral", img_fci);  
    349.       foregroundMaskAnalysis->process(frameNumber, "LBSimpleGaussian", img_lb_sg);  
    350.       foregroundMaskAnalysis->process(frameNumber, "LBFuzzyGaussian", img_lb_fg);  
    351.       foregroundMaskAnalysis->process(frameNumber, "LBMixtureOfGaussians", img_lb_mog);  
    352.       foregroundMaskAnalysis->process(frameNumber, "LBAdaptiveSOM", img_lb_som);  
    353.       foregroundMaskAnalysis->process(frameNumber, "LBFuzzyAdaptiveSOM", img_lb_fsom);  
    354.       foregroundMaskAnalysis->process(frameNumber, "LbpMrf", img_lbp_mrf);  
    355.       foregroundMaskAnalysis->process(frameNumber, "MultiLayerBGS", img_mlbgs);  
    356.       //foregroundMaskAnalysis->process(frameNumber, "PBAS", img_pt_pbas);  
    357.       foregroundMaskAnalysis->process(frameNumber, "VuMeter", img_vumeter);  
    358.       foregroundMaskAnalysis->process(frameNumber, "KDE", img_kde);  
    359.       foregroundMaskAnalysis->process(frameNumber, "IMBS", img_imbs);  
    360.       foregroundMaskAnalysis->process(frameNumber, "MultiCueBGS", img_mcbgs);  
    361.       foregroundMaskAnalysis->process(frameNumber, "SigmaDeltaBGS", img_sdbgs);  
    362.       foregroundMaskAnalysis->process(frameNumber, "SuBSENSEBGS", img_ssbgs);  
    363.       foregroundMaskAnalysis->process(frameNumber, "LOBSTERBGS", img_lobgs);  
    364.     }  
    365.   
    366.     firstTime = false;  
    367.   }  
    368.   
    369.   void FrameProcessor::finish(void)  
    370.   {  
    371.     /*if(enableMultiLayerBGS) 
    372.     multiLayerBGS->finish(); 
    373.  
    374.     if(enableLBSimpleGaussian) 
    375.     lbSimpleGaussian->finish(); 
    376.  
    377.     if(enableLBFuzzyGaussian) 
    378.     lbFuzzyGaussian->finish(); 
    379.  
    380.     if(enableLBMixtureOfGaussians) 
    381.     lbMixtureOfGaussians->finish(); 
    382.  
    383.     if(enableLBAdaptiveSOM) 
    384.     lbAdaptiveSOM->finish(); 
    385.  
    386.     if(enableLBFuzzyAdaptiveSOM) 
    387.     lbFuzzyAdaptiveSOM->finish();*/  
    388.   
    389.     if (enableForegroundMaskAnalysis)  
    390.       delete foregroundMaskAnalysis;  
    391.   
    392.     if (enableLOBSTERBGS)  
    393.       delete lobgs;  
    394.   
    395.     if (enableSuBSENSEBGS)  
    396.       delete ssbgs;  
    397.   
    398.     if (enableSigmaDeltaBGS)  
    399.       delete sdbgs;  
    400.   
    401.     if (enableMultiCueBGS)  
    402.       delete mcbgs;  
    403.   
    404.     if (enableIMBS)  
    405.       delete imbs;  
    406.   
    407.     if (enableKDE)  
    408.       delete kde;  
    409.   
    410.     if (enableVuMeter)  
    411.       delete vuMeter;  
    412.   
    413.     //if(enablePBAS)  
    414.     //  delete pixelBasedAdaptiveSegmenter;  
    415.   
    416.     if (enableMultiLayerBGS)  
    417.       delete multiLayerBGS;  
    418.   
    419.     if (enableLBFuzzyAdaptiveSOM)  
    420.       delete lbFuzzyAdaptiveSOM;  
    421.   
    422.     if (enableLBAdaptiveSOM)  
    423.       delete lbAdaptiveSOM;  
    424.   
    425.     if (enableLBMixtureOfGaussians)  
    426.       delete lbMixtureOfGaussians;  
    427.   
    428.     if (enableLBFuzzyGaussian)  
    429.       delete lbFuzzyGaussian;  
    430.   
    431.     if (enableLBSimpleGaussian)  
    432.       delete lbSimpleGaussian;  
    433.   
    434. #if !defined(_WIN32)  
    435.     if (enableLbpMrf)  
    436.       delete lbpMrf;  
    437. #endif  
    438.   
    439.     if(enableFuzzyChoquetIntegral)  
    440.       delete fuzzyChoquetIntegral;  
    441.   
    442.     if (enableFuzzySugenoIntegral)  
    443.       delete fuzzySugenoIntegral;  
    444.   
    445.     if (enableT2FMRF_UV)  
    446.       delete type2FuzzyMRF_UV;  
    447.   
    448.     if (enableT2FMRF_UM)  
    449.       delete type2FuzzyMRF_UM;  
    450.   
    451.     if (enableT2FGMM_UV)  
    452.       delete type2FuzzyGMM_UV;  
    453.   
    454.     if (enableT2FGMM_UM)  
    455.       delete type2FuzzyGMM_UM;  
    456.   
    457.     if (enableDPTextureBGS)  
    458.       delete textureBGS;  
    459.   
    460.     if (enableDPEigenbackgroundBGS)  
    461.       delete eigenBackground;  
    462.   
    463.     if (enableDPPratiMediodBGS)  
    464.       delete pratiMediod;  
    465.   
    466.     if (enableDPWrenGABGS)  
    467.       delete wrenGA;  
    468.   
    469.     if (enableDPMeanBGS)  
    470.       delete temporalMean;  
    471.   
    472.     if (enableDPZivkovicAGMMBGS)  
    473.       delete zivkovicAGMM;  
    474.   
    475.     if (enableDPGrimsonGMMBGS)  
    476.       delete grimsonGMM;  
    477.   
    478.     if (enableDPAdaptiveMedianBGS)  
    479.       delete adaptiveMedian;  
    480.   
    481. #if CV_MAJOR_VERSION >= 2 && CV_MINOR_VERSION >= 4 && CV_SUBMINOR_VERSION >= 3  
    482.     if (enableGMG)  
    483.       delete gmg;  
    484. #endif  
    485.   
    486.     if (enableAdaptiveBackgroundLearning)  
    487.       delete adaptiveBackgroundLearning;  
    488.   
    489.     if (enableMixtureOfGaussianV2BGS)  
    490.       delete mixtureOfGaussianV2BGS;  
    491.   
    492.     if (enableMixtureOfGaussianV1BGS)  
    493.       delete mixtureOfGaussianV1BGS;  
    494.   
    495.     if (enableWeightedMovingVarianceBGS)  
    496.       delete weightedMovingVariance;  
    497.   
    498.     if (enableWeightedMovingMeanBGS)  
    499.       delete weightedMovingMean;  
    500.   
    501.     if (enableStaticFrameDifferenceBGS)  
    502.       delete staticFrameDifference;  
    503.   
    504.     if (enableFrameDifferenceBGS)  
    505.       delete frameDifference;  
    506.   
    507.     if (enablePreProcessor)  
    508.       delete preProcessor;  
    509.   }  
    510.   
    511.   void FrameProcessor::tic(std::string value)  
    512.   {  
    513.     processname = value;  
    514.     duration = static_cast<double>(cv::getTickCount());  
    515.   }  
    516.   
    517.   void FrameProcessor::toc()  
    518.   {  
    519.     duration = (static_cast<double>(cv::getTickCount()) - duration) / cv::getTickFrequency();  
    520.     std::cout << processname << " time(sec):" << std::fixed << std::setprecision(6) << duration << std::endl;  
    521.   }  
    522.   
    523.   void FrameProcessor::saveConfig()  
    524.   {  
    525.     CvFileStorage* fs = cvOpenFileStorage("./config/FrameProcessor.xml", 0, CV_STORAGE_WRITE);  
    526.   
    527.     cvWriteString(fs, "tictoc", tictoc.c_str());  
    528.   
    529.     cvWriteInt(fs, "enablePreProcessor", enablePreProcessor);  
    530.   
    531.     cvWriteInt(fs, "enableForegroundMaskAnalysis", enableForegroundMaskAnalysis);  
    532.   
    533.     cvWriteInt(fs, "enableFrameDifferenceBGS", enableFrameDifferenceBGS);  
    534.     cvWriteInt(fs, "enableStaticFrameDifferenceBGS", enableStaticFrameDifferenceBGS);  
    535.     cvWriteInt(fs, "enableWeightedMovingMeanBGS", enableWeightedMovingMeanBGS);  
    536.     cvWriteInt(fs, "enableWeightedMovingVarianceBGS", enableWeightedMovingVarianceBGS);  
    537.     cvWriteInt(fs, "enableMixtureOfGaussianV1BGS", enableMixtureOfGaussianV1BGS);  
    538.     cvWriteInt(fs, "enableMixtureOfGaussianV2BGS", enableMixtureOfGaussianV2BGS);  
    539.     cvWriteInt(fs, "enableAdaptiveBackgroundLearning", enableAdaptiveBackgroundLearning);  
    540. #if CV_MAJOR_VERSION >= 2 && CV_MINOR_VERSION >= 4 && CV_SUBMINOR_VERSION >= 3  
    541.     cvWriteInt(fs, "enableGMG", enableGMG);  
    542. #endif  
    543.   
    544.     cvWriteInt(fs, "enableDPAdaptiveMedianBGS", enableDPAdaptiveMedianBGS);  
    545.     cvWriteInt(fs, "enableDPGrimsonGMMBGS", enableDPGrimsonGMMBGS);  
    546.     cvWriteInt(fs, "enableDPZivkovicAGMMBGS", enableDPZivkovicAGMMBGS);  
    547.     cvWriteInt(fs, "enableDPMeanBGS", enableDPMeanBGS);  
    548.     cvWriteInt(fs, "enableDPWrenGABGS", enableDPWrenGABGS);  
    549.     cvWriteInt(fs, "enableDPPratiMediodBGS", enableDPPratiMediodBGS);  
    550.     cvWriteInt(fs, "enableDPEigenbackgroundBGS", enableDPEigenbackgroundBGS);  
    551.     cvWriteInt(fs, "enableDPTextureBGS", enableDPTextureBGS);  
    552.   
    553.     cvWriteInt(fs, "enableT2FGMM_UM", enableT2FGMM_UM);  
    554.     cvWriteInt(fs, "enableT2FGMM_UV", enableT2FGMM_UV);  
    555.     cvWriteInt(fs, "enableT2FMRF_UM", enableT2FMRF_UM);  
    556.     cvWriteInt(fs, "enableT2FMRF_UV", enableT2FMRF_UV);  
    557.     cvWriteInt(fs, "enableFuzzySugenoIntegral", enableFuzzySugenoIntegral);  
    558.     cvWriteInt(fs, "enableFuzzyChoquetIntegral", enableFuzzyChoquetIntegral);  
    559.   
    560.     cvWriteInt(fs, "enableLBSimpleGaussian", enableLBSimpleGaussian);  
    561.     cvWriteInt(fs, "enableLBFuzzyGaussian", enableLBFuzzyGaussian);  
    562.     cvWriteInt(fs, "enableLBMixtureOfGaussians", enableLBMixtureOfGaussians);  
    563.     cvWriteInt(fs, "enableLBAdaptiveSOM", enableLBAdaptiveSOM);  
    564.     cvWriteInt(fs, "enableLBFuzzyAdaptiveSOM", enableLBFuzzyAdaptiveSOM);  
    565.   
    566.     cvWriteInt(fs, "enableLbpMrf", enableLbpMrf);  
    567.   
    568.     cvWriteInt(fs, "enableMultiLayerBGS", enableMultiLayerBGS);  
    569.     //cvWriteInt(fs, "enablePBAS", enablePBAS);  
    570.     cvWriteInt(fs, "enableVuMeter", enableVuMeter);  
    571.     cvWriteInt(fs, "enableKDE", enableKDE);  
    572.     cvWriteInt(fs, "enableIMBS", enableIMBS);  
    573.     cvWriteInt(fs, "enableMultiCueBGS", enableMultiCueBGS);  
    574.     cvWriteInt(fs, "enableSigmaDeltaBGS", enableSigmaDeltaBGS);  
    575.     cvWriteInt(fs, "enableSuBSENSEBGS", enableSuBSENSEBGS);  
    576.     cvWriteInt(fs, "enableLOBSTERBGS", enableLOBSTERBGS);  
    577.   
    578.     cvReleaseFileStorage(&fs);  
    579.   }  
    580.   
    581.   void FrameProcessor::loadConfig()  
    582.   {  
    583.     CvFileStorage* fs = cvOpenFileStorage("./config/FrameProcessor.xml", 0, CV_STORAGE_READ);  
    584.   
    585.     tictoc = cvReadStringByName(fs, 0, "tictoc", "");  
    586.   
    587.     enablePreProcessor = cvReadIntByName(fs, 0, "enablePreProcessor", true);  
    588.   
    589.     enableForegroundMaskAnalysis = cvReadIntByName(fs, 0, "enableForegroundMaskAnalysis", false);  
    590.   
    591.     enableFrameDifferenceBGS = cvReadIntByName(fs, 0, "enableFrameDifferenceBGS", false);  
    592.     enableStaticFrameDifferenceBGS = cvReadIntByName(fs, 0, "enableStaticFrameDifferenceBGS", false);  
    593.     enableWeightedMovingMeanBGS = cvReadIntByName(fs, 0, "enableWeightedMovingMeanBGS", false);  
    594.     enableWeightedMovingVarianceBGS = cvReadIntByName(fs, 0, "enableWeightedMovingVarianceBGS", false);  
    595.     enableMixtureOfGaussianV1BGS = cvReadIntByName(fs, 0, "enableMixtureOfGaussianV1BGS", false);  
    596.     enableMixtureOfGaussianV2BGS = cvReadIntByName(fs, 0, "enableMixtureOfGaussianV2BGS", false);  
    597.     enableAdaptiveBackgroundLearning = cvReadIntByName(fs, 0, "enableAdaptiveBackgroundLearning", false);  
    598. #if CV_MAJOR_VERSION >= 2 && CV_MINOR_VERSION >= 4 && CV_SUBMINOR_VERSION >= 3  
    599.     enableGMG = cvReadIntByName(fs, 0, "enableGMG", false);  
    600. #endif  
    601.   
    602.     enableDPAdaptiveMedianBGS = cvReadIntByName(fs, 0, "enableDPAdaptiveMedianBGS", false);  
    603.     enableDPGrimsonGMMBGS = cvReadIntByName(fs, 0, "enableDPGrimsonGMMBGS", false);  
    604.     enableDPZivkovicAGMMBGS = cvReadIntByName(fs, 0, "enableDPZivkovicAGMMBGS", false);  
    605.     enableDPMeanBGS = cvReadIntByName(fs, 0, "enableDPMeanBGS", false);  
    606.     enableDPWrenGABGS = cvReadIntByName(fs, 0, "enableDPWrenGABGS", false);  
    607.     enableDPPratiMediodBGS = cvReadIntByName(fs, 0, "enableDPPratiMediodBGS", false);  
    608.     enableDPEigenbackgroundBGS = cvReadIntByName(fs, 0, "enableDPEigenbackgroundBGS", false);  
    609.     enableDPTextureBGS = cvReadIntByName(fs, 0, "enableDPTextureBGS", false);  
    610.   
    611.     enableT2FGMM_UM = cvReadIntByName(fs, 0, "enableT2FGMM_UM", false);  
    612.     enableT2FGMM_UV = cvReadIntByName(fs, 0, "enableT2FGMM_UV", false);  
    613.     enableT2FMRF_UM = cvReadIntByName(fs, 0, "enableT2FMRF_UM", false);  
    614.     enableT2FMRF_UV = cvReadIntByName(fs, 0, "enableT2FMRF_UV", false);  
    615.     enableFuzzySugenoIntegral = cvReadIntByName(fs, 0, "enableFuzzySugenoIntegral", false);  
    616.     enableFuzzyChoquetIntegral = cvReadIntByName(fs, 0, "enableFuzzyChoquetIntegral", false);  
    617.   
    618.     enableLBSimpleGaussian = cvReadIntByName(fs, 0, "enableLBSimpleGaussian", false);  
    619.     enableLBFuzzyGaussian = cvReadIntByName(fs, 0, "enableLBFuzzyGaussian", false);  
    620.     enableLBMixtureOfGaussians = cvReadIntByName(fs, 0, "enableLBMixtureOfGaussians", false);  
    621.     enableLBAdaptiveSOM = cvReadIntByName(fs, 0, "enableLBAdaptiveSOM", false);  
    622.     enableLBFuzzyAdaptiveSOM = cvReadIntByName(fs, 0, "enableLBFuzzyAdaptiveSOM", false);  
    623.   
    624.     enableLbpMrf = cvReadIntByName(fs, 0, "enableLbpMrf", false);  
    625.   
    626.     enableMultiLayerBGS = cvReadIntByName(fs, 0, "enableMultiLayerBGS", false);  
    627.     //enablePBAS = cvReadIntByName(fs, 0, "enablePBAS", false);  
    628.     enableVuMeter = cvReadIntByName(fs, 0, "enableVuMeter", false);  
    629.     enableKDE = cvReadIntByName(fs, 0, "enableKDE", false);  
    630.     enableIMBS = cvReadIntByName(fs, 0, "enableIMBS", false);  
    631.     enableMultiCueBGS = cvReadIntByName(fs, 0, "enableMultiCueBGS", false);  
    632.     enableSigmaDeltaBGS = cvReadIntByName(fs, 0, "enableSigmaDeltaBGS", false);  
    633.     enableSuBSENSEBGS = cvReadIntByName(fs, 0, "enableSuBSENSEBGS", false);  
    634.     enableLOBSTERBGS = cvReadIntByName(fs, 0, "enableLOBSTERBGS", false);  
    635.   
    636.     cvReleaseFileStorage(&fs);  
    637.   }  
    638. }  


    其实,从源码中可以看出,本函数所做的工作并不多,主要就是调用背景建模算法的接口,其接口处是:bgs->process(img_input, img_bgs, img_bkgmodel);

    下面给出此段代码的大致流程框架图:

  • 相关阅读:
    白帽子 攻防
    自定义WCF的配置文件
    .net快速创建PDF文档 by c#
    如何在面试中发现优秀程序员
    kafka-java客户端连接
    xshell 登陆堡垒机实现自动跳转
    良好的编程习惯
    Mycat-介绍
    scala-传名函数和传值函数
    springboot-31-springboot静态注入
  • 原文地址:https://www.cnblogs.com/ywsoftware/p/4511780.html
Copyright © 2020-2023  润新知