Path: blob/master/Background-Subtraction/background_subtr_bgslib.cpp
3119 views
#include <iostream>1#include <algorithm>2#include <iterator>3#include <vector>4#include <opencv2/videoio.hpp>56#include "algorithms/algorithms.h"78using namespace cv;9using namespace std;1011const char* input_params = "{ input | space_traffic.mp4 | Define the full input video path }";1213void get_bgslib_result(String video_to_process)14{15// create VideoCapture object for further video processing16VideoCapture capture(samples::findFile(video_to_process));17if (!capture.isOpened()) {18//error in opening the video input19cerr << "Unable to open: " << video_to_process << endl;20return;21}2223// instantiate background subtraction model24SuBSENSE background_subtr_method = SuBSENSE();2526Mat frame, fgMask, background;27while (true) {28capture >> frame;2930// check whether the frames have been grabbed31if (frame.empty())32break;3334// resize video frames35resize(frame, frame, Size(640, 360));3637try38{39// pass the frame to the model processor40background_subtr_method.process(frame, fgMask, background);41}42catch (exception& e)43{44cout << "Exception occurred" << endl;45cout << e.what() << endl;46}4748// show the current frame, foreground mask, subtracted result49imshow("Initial Frames", frame);50imshow("Foreground Masks", fgMask);51imshow("Subtraction Result", background);5253int keyboard = waitKey(10);54if (keyboard == 27)55break;56}57}5859int main(int argc, char* argv[])60{61CommandLineParser parser(argc, argv, input_params);62// start BS-pipeline63get_bgslib_result(parser.get<String>("input"));6465return 0;66}6768