Mercurial Hosting > traffic-intelligence
diff c/feature-based-tracking.cpp @ 399:c389fae9689a
Added a class to read list of image instead of video. This is controlled by the use of the database-filename and folder-data parameters in the config file.
author | Jean-Philippe Jodoin <jpjodoin@gmail.com> |
---|---|
date | Mon, 29 Jul 2013 17:12:45 -0400 |
parents | 03dbecd3a887 |
children | 7ef1071e3cc3 |
line wrap: on
line diff
--- a/c/feature-based-tracking.cpp Mon Jul 29 13:46:07 2013 -0400 +++ b/c/feature-based-tracking.cpp Mon Jul 29 17:12:45 2013 -0400 @@ -17,6 +17,10 @@ #include <boost/shared_ptr.hpp> #include <boost/foreach.hpp> +#include "InputVideoFileModule.h" +#include "InputFrameListModule.h" + + #include <iostream> #include <vector> #include <ctime> @@ -78,28 +82,27 @@ // BruteForceMatcher<Hamming> descMatcher; // vector<DMatch> matches; - VideoCapture capture; - Size videoSize; - unsigned int nFrames = 0; - capture.open(params.videoFilename); - if(capture.isOpened()) { - videoSize = Size(capture.get(CV_CAP_PROP_FRAME_WIDTH), capture.get(CV_CAP_PROP_FRAME_HEIGHT)); - nFrames = capture.get(CV_CAP_PROP_FRAME_COUNT); - cout << "Video " << params.videoFilename << - ": width=" << videoSize.width << - ", height=" << videoSize.height << - ", nframes=" << nFrames << endl; - } else { - cout << "Video filename " << params.videoFilename << " could not be opened. Exiting." << endl; - exit(0); + InputFrameProviderIface* capture = nullptr; + if(!params.listFilename.empty() && !params.folderData.empty()) + capture = new InputFrameListModule(params.folderData, params.listFilename); + else if(!params.videoFilename.empty()) + capture = new InputVideoFileModule(params.videoFilename); + else + cout << "No valid input parameters"; + + if(!capture->isOpen()) + { + cout << "Video filename " << params.videoFilename << " could not be opened. Exiting." << endl; + exit(0); } - // if (!capture.isOpened()) - // { - // //help(argv); - // cout << "capture device " << argv[1] << " failed to open!" << endl; - // return 1; - // } - + + Size videoSize = capture->getSize(); + unsigned int nFrames = capture->getNbFrames(); + cout << "Video " << params.videoFilename << + ": width=" << videoSize.width << + ", height=" << videoSize.height << + ", nframes=" << nFrames << endl; + Mat mask = imread(params.maskFilename, 0); if (mask.empty()) { cout << "Mask filename " << params.maskFilename << " could not be opened." << endl; @@ -135,9 +138,9 @@ //capture.set(CV_CAP_PROP_POS_FRAMES, params.frame1); for (unsigned int frameNum = params.frame1; (frameNum < lastFrameNum) && !::interruptionKey(key); frameNum++) { - capture >> frame; + bool success = capture->getNextFrame(frame); - if (frame.empty() || frame.size() != videoSize) + if (!success || frame.empty() || frame.size() != videoSize) break; if (frameNum%50 ==0) @@ -243,6 +246,8 @@ trajectoryDB->endTransaction(); trajectoryDB->disconnect(); + delete capture; + } void groupFeatures(const KLTFeatureTrackingParameters& params) {