Skip to content
Snippets Groups Projects
Select Git revision
  • 56481e1e014ef8744c81089904b30b2fe9213a29
  • master default protected
  • beta
  • dev
  • andrewssobral-patch-1
  • update
  • thomas-fork
  • 2.0
  • v3.2.0
  • v3.1.0
  • v3.0
  • bgslib_py27_ocv3_win64
  • bgslib_java_2.0.0
  • bgslib_console_2.0.0
  • bgslib_matlab_win64_2.0.0
  • bgslib_qtgui_2.0.0
  • 2.0.0
  • bgs_console_2.0.0
  • bgs_matlab_win64_2.0.0
  • bgs_qtgui_2.0.0
  • v1.9.2_x86_mfc_gui
  • v1.9.2_x64_java_gui
  • v1.9.2_x86_java_gui
23 results

FrameProcessor.cpp

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    T2FGMM_UV.cpp 2.44 KiB
    #include "T2FGMM_UV.h"
    
    #if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
    
    using namespace bgslibrary::algorithms;
    
    T2FGMM_UV::T2FGMM_UV() :
      IBGS(quote(T2FGMM_UV)),
      frameNumber(0), threshold(9.0), alpha(0.01), 
      km(1.5f), kv(0.6f), gaussians(3)
    {
      debug_construction(T2FGMM_UV);
      initLoadSaveConfig(algorithmName);
    }
    
    T2FGMM_UV::~T2FGMM_UV() {
      debug_destruction(T2FGMM_UV);
    }
    
    void T2FGMM_UV::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel)
    {
      init(img_input, img_output, img_bgmodel);
      frame = new IplImage(img_input);
    
      if (firstTime)
        frame_data.ReleaseMemory(false);
      frame_data = frame;
    
      if (firstTime) {
        int width = img_input.size().width;
        int height = img_input.size().height;
    
        lowThresholdMask = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
        lowThresholdMask.Ptr()->origin = IPL_ORIGIN_BL;
    
        highThresholdMask = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
        highThresholdMask.Ptr()->origin = IPL_ORIGIN_BL;
    
        params.SetFrameSize(width, height);
        params.LowThreshold() = threshold;
        params.HighThreshold() = 2 * params.LowThreshold();
        params.Alpha() = alpha;
        params.MaxModes() = gaussians;
        params.Type() = dp::TYPE_T2FGMM_UV;
        params.KM() = km; // Factor control for the T2FGMM-UM [0,3] default: 1.5
        params.KV() = kv; // Factor control for the T2FGMM-UV [0.3,1] default: 0.6
    
        bgs.Initalize(params);
        bgs.InitModel(frame_data);
      }
    
      bgs.Subtract(frameNumber, frame_data, lowThresholdMask, highThresholdMask);
      lowThresholdMask.Clear();
      bgs.Update(frameNumber, frame_data, lowThresholdMask);
    
      img_foreground = cv::cvarrToMat(highThresholdMask.Ptr());
      img_background = cv::cvarrToMat(bgs.Background()->Ptr());
      //img_background = cv::Mat::zeros(img_input.size(), img_input.type());
    
    #ifndef MEX_COMPILE_FLAG
      if (showOutput)
        cv::imshow(algorithmName + "_FG", img_foreground);
    #endif
    
      img_foreground.copyTo(img_output);
      img_background.copyTo(img_bgmodel);
    
      delete frame;
      firstTime = false;
      frameNumber++;
    }
    
    void T2FGMM_UV::save_config(cv::FileStorage &fs) {
      fs << "threshold" << threshold;
      fs << "alpha" << alpha;
      fs << "km" << km;
      fs << "kv" << kv;
      fs << "gaussians" << gaussians;
      fs << "showOutput" << showOutput;
    }
    
    void T2FGMM_UV::load_config(cv::FileStorage &fs) {
      fs["threshold"] >> threshold;
      fs["alpha"] >> alpha;
      fs["km"] >> km;
      fs["kv"] >> kv;
      fs["gaussians"] >> gaussians;
      fs["showOutput"] >> showOutput;
    }
    
    #endif