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

VideoAnalysis.cpp

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    VideoAnalysis.cpp 4.48 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 "VideoAnalysis.h"
    
    namespace bgslibrary
    {
      VideoAnalysis::VideoAnalysis() :
        use_file(false), use_camera(false), cameraIndex(0),
        use_comp(false), frameToStop(0)
      {
        std::cout << "VideoAnalysis()" << std::endl;
      }
    
      VideoAnalysis::~VideoAnalysis()
      {
        std::cout << "~VideoAnalysis()" << std::endl;
      }
    
      bool VideoAnalysis::setup(int argc, const char **argv)
      {
        bool flag = false;
    
    #if CV_MAJOR_VERSION == 2
        const char* keys =
          "{hp|help|false|Print this message}"
          "{uf|use_file|false|Use video file}"
          "{fn|filename||Specify video file}"
          "{uc|use_cam|false|Use camera}"
          "{ca|camera|0|Specify camera index}"
          "{co|use_comp|false|Use mask comparator}"
          "{st|stopAt|0|Frame number to stop}"
          "{im|imgref||Specify image file}"
          ;
    #elif CV_MAJOR_VERSION == 3
        const std::string keys =
          "{h help ?     |     | Print this message   }"
          "{uf use_file  |false| Use a video file     }"
          "{fn filename  |     | Specify a video file }"
          "{uc use_cam   |false| Use a webcamera      }"
          "{ca camera    | 0   | Specify camera index }"
          "{co use_comp  |false| Use mask comparator  }"
          "{st stopAt    | 0   | Frame number to stop }"
          "{im imgref    |     | Specify a image file }"
          ;
    #endif
    
        cv::CommandLineParser cmd(argc, argv, keys);
    
    #if CV_MAJOR_VERSION == 2
        if (argc <= 1 || cmd.get<bool>("help") == true)
        {
          std::cout << "Usage: " << argv[0] << " [options]" << std::endl;
          std::cout << "Available options:" << std::endl;
          cmd.printParams();
          return false;
        }
    #elif CV_MAJOR_VERSION == 3
        if (argc <= 1 || cmd.has("help"))
        {
          std::cout << "Usage: " << argv[0] << " [options]" << std::endl;
          std::cout << "Available options:" << std::endl;
          cmd.printMessage();
          return false;
        }
        if (!cmd.check())
        {
          cmd.printErrors();
          return false;
        }
    #endif
    
        use_file = cmd.get<bool>("uf"); //use_file
        filename = cmd.get<std::string>("fn"); //filename
        use_camera = cmd.get<bool>("uc"); //use_cam
        cameraIndex = cmd.get<int>("ca"); //camera
        use_comp = cmd.get<bool>("co"); //use_comp
        frameToStop = cmd.get<int>("st"); //stopAt
        imgref = cmd.get<std::string>("im"); //imgref
    
        std::cout << "use_file:    " << use_file << std::endl;
        std::cout << "filename:    " << filename << std::endl;
        std::cout << "use_camera:  " << use_camera << std::endl;
        std::cout << "cameraIndex: " << cameraIndex << std::endl;
        std::cout << "use_comp:    " << use_comp << std::endl;
        std::cout << "frameToStop: " << frameToStop << std::endl;
        std::cout << "imgref:      " << imgref << std::endl;
        //return false;
    
        if (use_file)
        {
          if (filename.empty())
          {
            std::cout << "Specify filename" << std::endl;
            return false;
          }
    
          flag = true;
        }
    
        if (use_camera)
          flag = true;
    
        if (flag && use_comp)
        {
          if (imgref.empty())
          {
            std::cout << "Specify image reference" << std::endl;
            return false;
          }
        }
    
        return flag;
      }
    
      void VideoAnalysis::start()
      {
        //std::cout << "Press 'ESC' to stop..." << std::endl;
    
        do
        {
          videoCapture = new VideoCapture;
          frameProcessor = new FrameProcessor;
    
          frameProcessor->init();
          frameProcessor->frameToStop = frameToStop;
          frameProcessor->imgref = imgref;
    
          videoCapture->setFrameProcessor(frameProcessor);
    
          if (use_file)
            videoCapture->setVideo(filename);
    
          if (use_camera)
            videoCapture->setCamera(cameraIndex);
    
          videoCapture->start();
    
          if (use_file || use_camera)
            break;
    
          frameProcessor->finish();
    
          int key = cvWaitKey(500);
          if (key == KEY_ESC)
            break;
    
          delete frameProcessor;
          delete videoCapture;
    
        } while (1);
    
        delete frameProcessor;
        delete videoCapture;
      }
    }