Skip to content
Snippets Groups Projects
Select Git revision
  • e7cc79f02ca06a1d8a53495190ad9fba07857896
  • 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

IndependentMultimodalBGS.cpp

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    FrameDifferenceBGS.cpp 2.28 KiB
    /*
    This file is part of BGSLibrary.
    
    BGSLibrary is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
    
    BGSLibrary is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
    along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
    */
    #include "FrameDifferenceBGS.h"
    
    FrameDifferenceBGS::FrameDifferenceBGS() : firstTime(true), enableThreshold(true), threshold(15), showOutput(true)
    {
      std::cout << "FrameDifferenceBGS()" << std::endl;
    }
    
    FrameDifferenceBGS::~FrameDifferenceBGS()
    {
      std::cout << "~FrameDifferenceBGS()" << std::endl;
    }
    
    void FrameDifferenceBGS::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel)
    {
      if(img_input.empty())
        return;
    
      loadConfig();
    
      if(firstTime)
        saveConfig();
    
      if(img_input_prev.empty())
      {
        img_input.copyTo(img_input_prev);
        return;
      }
    
      cv::absdiff(img_input_prev, img_input, img_foreground);
    
      if(img_foreground.channels() == 3)
        cv::cvtColor(img_foreground, img_foreground, CV_BGR2GRAY);
    
      if(enableThreshold)
        cv::threshold(img_foreground, img_foreground, threshold, 255, cv::THRESH_BINARY);
    
      if(showOutput)
        cv::imshow("Frame Difference", img_foreground);
    
      img_foreground.copyTo(img_output);
    
      img_input.copyTo(img_input_prev);
    
      firstTime = false;
    }
    
    void FrameDifferenceBGS::saveConfig()
    {
      CvFileStorage* fs = cvOpenFileStorage("./config/FrameDifferenceBGS.xml", 0, CV_STORAGE_WRITE);
    
      cvWriteInt(fs, "enableThreshold", enableThreshold);
      cvWriteInt(fs, "threshold", threshold);
      cvWriteInt(fs, "showOutput", showOutput);
    
      cvReleaseFileStorage(&fs);
    }
    
    void FrameDifferenceBGS::loadConfig()
    {
      CvFileStorage* fs = cvOpenFileStorage("./config/FrameDifferenceBGS.xml", 0, CV_STORAGE_READ);
      
      enableThreshold = cvReadIntByName(fs, 0, "enableThreshold", true);
      threshold = cvReadIntByName(fs, 0, "threshold", 15);
      showOutput = cvReadIntByName(fs, 0, "showOutput", true);
    
      cvReleaseFileStorage(&fs);
    }