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

Demo_orig.cpp

  • user avatar
    .
    am0ebe authored
    ed6b10cc
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    Demo_orig.cpp 2.93 KiB
    #include <iostream>
    #include <algorithm>
    #include <iterator>
    #include <string>
    #include <vector>
    #include <opencv2/opencv.hpp>
    
    #include "../src/algorithms/algorithms.h"
    
    using namespace bgslibrary::algorithms;
    
    /* Background Subtraction Methods */
    auto algorithmsName = BGS_Factory::Instance()->GetRegisteredAlgorithmsName();
    
    int main(int argc, char** argv)
    {
      std::cout << "Using OpenCV " << CV_MAJOR_VERSION << "." << CV_MINOR_VERSION << "." << CV_SUBMINOR_VERSION << std::endl;
    
      std::cout << "Number of available algorithms: " << algorithmsName.size() << std::endl;
      std::cout << "List of available algorithms:" << std::endl;
      std::copy(algorithmsName.begin(), algorithmsName.end(), std::ostream_iterator<std::string>(std::cout, "\n"));
    
      /*
      Codebook is new!
      Tapter is TBoy!
       List of all algorithms:
       (Note that some of these algorithms are available only for a specific version of OpenCV, see algorithms.h)
       AdaptiveBackgroundLearning,AdaptiveSelectiveBackgroundLearning,CodeBook,DPAdaptiveMedian,DPEigenbackground,
       DPGrimsonGMM,DPMean,DPPratiMediod,DPTexture,DPWrenGA,DPZivkovicAGMM,FrameDifference,FuzzyChoquetIntegral,
       FuzzySugenoIntegral,GMG,IndependentMultimodal,KDE,KNN,LBAdaptiveSOM,LBFuzzyAdaptiveSOM,LBFuzzyGaussian,
       LBMixtureOfGaussians,LBP_MRF,LBSimpleGaussian,LOBSTER,MixtureOfGaussianV2,MixtureOfGaussianV1,MultiCue,
       MultiLayer,PAWCS,PixelBasedAdaptiveSegmenter,SigmaDelta,StaticFrameDifference,SuBSENSE,T2FGMM_UM,T2FGMM_UV,
       T2FMRF_UM,T2FMRF_UV,TwoPoints,ViBe,VuMeter,WeightedMovingMean,WeightedMovingVariance
      */
      std::string algorithmName = "FrameDifference";
      int cameraIndex = 0;
      if (argc > 1) algorithmName = argv[1];
      if (argc > 2) cameraIndex = std::stoi(argv[2]);
    
      cv::VideoCapture capture;
      capture.open(cameraIndex);
    
      if (!capture.isOpened()) {
        std::cerr << "Cannot initialize web camera!" << std::endl;
        return -1;
      }
    
      std::cout << "Running " << algorithmName << std::endl;
      auto bgs = BGS_Factory::Instance()->Create(algorithmName);
    
      cv::Mat img_input;
      auto key = 0;
      std::cout << "Press 's' to stop:" << std::endl;
      while (key != 's') {
        // Capture frame-by-frame
        capture >> img_input;
    
        if (img_input.empty()) break;
    
        // Resize input frame for better visualization
        cv::resize(img_input, img_input, cv::Size(380, 240), 0, 0, CV_INTER_LINEAR);
        cv::imshow("input", img_input);
    
        cv::Mat img_mask;
        cv::Mat img_bkgmodel;
        try {
          // by default, bgs->process(...) shows automatically the foreground mask image
          // or you can disable it by: bgs->setShowOutput(false);
          bgs->process(img_input, img_mask, img_bkgmodel);
    
          //if(!img_mask.empty())
          //  cv::imshow("Foreground", img_mask);
          //  ....do something else...
        }
        catch (std::exception& e) {
          std::cout << "Exception occurred" << std::endl;
          std::cout << e.what() << std::endl;
        }
    
        key = cv::waitKey(33);
      }
    
      cv::destroyAllWindows();
      capture.release();
    
      return 0;
    }