Mercurial Hosting > traffic-intelligence
changeset 401:b829ebdc18e6
simplified input of directories of video frames (simply use the video filename parameter to point at the directory)
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Mon, 29 Jul 2013 18:58:05 -0400 |
parents | 7ef1071e3cc3 |
children | f29204e68aab |
files | c/InputFrameListModule.cpp c/InputVideoFileModule.cpp c/Makefile c/feature-based-tracking.cpp include/InputFrameListModule.h include/InputFrameProviderIface.h include/InputVideoFileModule.h |
diffstat | 7 files changed, 54 insertions(+), 63 deletions(-) [+] |
line wrap: on
line diff
--- a/c/InputFrameListModule.cpp Mon Jul 29 18:06:55 2013 -0400 +++ b/c/InputFrameListModule.cpp Mon Jul 29 18:58:05 2013 -0400 @@ -4,62 +4,58 @@ #include <fstream> #include <ostream> #include <iostream> +#include <algorithm> + +//#include <boost/algorithm/string.hpp> +#include <boost/filesystem.hpp> #include "opencv2/core/core.hpp" #include "opencv2/highgui/highgui.hpp" -InputFrameListModule::InputFrameListModule(const std::string& basePath, const std::string& pictureList) - : mCurrentIdx(0), mInit(false), mBasePath(basePath+"/") { - loadFileList(pictureList); -} -InputFrameListModule::~InputFrameListModule() -{ +namespace fs = boost::filesystem; +InputFrameListModule::InputFrameListModule(const std::string& _dirname) + : mCurrentIdx(0), mInit(false), dirname(_dirname){ + loadImageList(); } +InputFrameListModule::~InputFrameListModule(void) { } +void InputFrameListModule::setFrameNumber(const unsigned int& frameNumber) { + if (frameNumber < filenames.size()) + mCurrentIdx = frameNumber; + else + mCurrentIdx = filenames.size()-1; +} + bool InputFrameListModule::getNextFrame(cv::Mat& mat) { bool success = false; - if(mCurrentIdx < mFileList.size()) - { - const std::string& fileName = mBasePath+mFileList[mCurrentIdx++]; - mCurrentFrame = cv::imread(fileName); + if(mCurrentIdx < filenames.size()) { + mat = cv::imread(dirname+filenames[mCurrentIdx++]); - if(!mCurrentFrame.empty()) + if(!mat.empty()) success = true; - mat = mCurrentFrame; } - return success; } -unsigned int InputFrameListModule::getNbFrames() -{ - return mFileList.size(); +unsigned int InputFrameListModule::getNbFrames(void) { + return filenames.size(); } -void InputFrameListModule::loadFileList(const std::string& path) -{ - std::ifstream inputFile((mBasePath+path).c_str()); - ::openCheck(inputFile, mBasePath+path, "InputFrameListModule::loadFileList"); - std::string str; - while( !inputFile.eof() ) - { - std::getline(inputFile, str); - if (str.empty()) - break; - if (str.at(0) == '#' ) - continue; /* comment */ - mFileList.push_back(str); - } - - if(!mFileList.empty()) - { - cv::Mat tmpImg = cv::imread(mBasePath+mFileList[0]); - mSize = cv::Size(tmpImg.cols, tmpImg.rows); - mInit = true; - } +void InputFrameListModule::loadImageList(void) { + for (fs::directory_iterator iter(dirname); iter!=fs::directory_iterator(); iter++) + filenames.push_back(iter->path().filename().string()); + + sort(filenames.begin(), filenames.end()); + + if(!filenames.empty()) { + std::cout << dirname+filenames[0] << std::endl; + cv::Mat tmpImg = cv::imread(dirname+filenames[0]); + mSize = cv::Size(tmpImg.cols, tmpImg.rows); + mInit = true; + } }
--- a/c/InputVideoFileModule.cpp Mon Jul 29 18:06:55 2013 -0400 +++ b/c/InputVideoFileModule.cpp Mon Jul 29 18:58:05 2013 -0400 @@ -14,7 +14,7 @@ InputVideoFileModule::~InputVideoFileModule(void) { } -void InputVideoFileModule::setFrameNumber(const int& frameNumber) { +void InputVideoFileModule::setFrameNumber(const unsigned int& frameNumber) { mVideoCapture.set(CV_CAP_PROP_POS_FRAMES, frameNumber); } @@ -23,7 +23,7 @@ bool success = false; if(mInit) { - mVideoCapture >> outputPicture; + mVideoCapture >> outputPicture; success = !outputPicture.empty(); } return success;
--- a/c/Makefile Mon Jul 29 18:06:55 2013 -0400 +++ b/c/Makefile Mon Jul 29 18:58:05 2013 -0400 @@ -10,8 +10,7 @@ LDFLAGS = -lm LDFLAGS += -lTrajectoryManagementAndAnalysis -lsqlite3 -LDFLAGS += -lboost_program_options -# -lboost_filesystem-mt -lboost_system-mt +LDFLAGS += -lboost_program_options -lboost_filesystem -lboost_system #LDFLAGS += -lfltk CFLAGS = -Wall -W -Wextra
--- a/c/feature-based-tracking.cpp Mon Jul 29 18:06:55 2013 -0400 +++ b/c/feature-based-tracking.cpp Mon Jul 29 18:58:05 2013 -0400 @@ -16,17 +16,18 @@ #include <boost/shared_ptr.hpp> #include <boost/foreach.hpp> +#include <boost/filesystem.hpp> #include "InputVideoFileModule.h" #include "InputFrameListModule.h" - #include <iostream> #include <vector> #include <ctime> using namespace std; using namespace cv; +namespace fs = boost::filesystem; void drawMatchesRelative(const vector<KeyPoint>& train, const vector<KeyPoint>& query, std::vector<cv::DMatch>& matches, Mat& img) { for (int i = 0; i < (int)matches.size(); i++) @@ -82,13 +83,13 @@ // BruteForceMatcher<Hamming> descMatcher; // vector<DMatch> matches; - InputFrameProviderIface* capture = 0; - if(!params.listFilename.empty() && !params.folderData.empty()) - capture = new InputFrameListModule(params.folderData, params.listFilename); + boost::shared_ptr<InputFrameProviderIface> capture; + if (fs::is_directory(fs::path(params.videoFilename))) + capture = boost::shared_ptr<InputFrameListModule>(new InputFrameListModule(params.videoFilename)); else if(!params.videoFilename.empty()) - capture = new InputVideoFileModule(params.videoFilename); + capture = boost::shared_ptr<InputVideoFileModule>(new InputVideoFileModule(params.videoFilename)); else - cout << "No valid input parameters"; + cout << "No valid input parameters" << endl; if(!capture->isOpen()) { cout << "Video filename " << params.videoFilename << " could not be opened. Exiting." << endl; @@ -124,8 +125,8 @@ std::vector<FeatureTrajectoryPtr> lostFeatures; std::vector<FeaturePointMatch> featurePointMatches; - HOGDescriptor hog; - hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector()); + //HOGDescriptor hog; + //hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector()); int key = '?'; unsigned int savedFeatureId=0; @@ -233,8 +234,8 @@ //brief.compute(currentFrameBW, currKpts, currDesc); //Compute brief descriptors at each keypoint location if (params.display) { + imshow("mask", featureMask*256); imshow("frame", frame); - imshow("mask", featureMask*256); key = waitKey(2); } previousFrameBW = currentFrameBW.clone(); @@ -245,8 +246,6 @@ trajectoryDB->endTransaction(); trajectoryDB->disconnect(); - delete capture; - } void groupFeatures(const KLTFeatureTrackingParameters& params) {
--- a/include/InputFrameListModule.h Mon Jul 29 18:06:55 2013 -0400 +++ b/include/InputFrameListModule.h Mon Jul 29 18:58:05 2013 -0400 @@ -2,32 +2,29 @@ #define INPUT_FRAME_LIST_MODULE_H #include "InputFrameProviderIface.h" + #include <string> #include <vector> class InputFrameListModule : public InputFrameProviderIface { public: - InputFrameListModule(const std::string& basePath,const std::string& pictureList); + InputFrameListModule(const std::string& _dirname); ~InputFrameListModule(); - - bool getNextFrame(cv::Mat&); unsigned int getNbFrames(); bool isOpen() const { return mInit;} - void setFrameNumber(const int& frameNumber) {} // does nothing for now + void setFrameNumber(const unsigned int& frameNumber); virtual const cv::Size& getSize() const { return mSize;} private: - void loadFileList(const std::string& path); - std::vector<std::string> mFileList; + void loadImageList(void); + std::vector<std::string> filenames; unsigned int mCurrentIdx; bool mInit; - std::string mBasePath; - cv::Mat mCurrentFrame; + std::string dirname; cv::Size mSize; - }; #endif
--- a/include/InputFrameProviderIface.h Mon Jul 29 18:06:55 2013 -0400 +++ b/include/InputFrameProviderIface.h Mon Jul 29 18:58:05 2013 -0400 @@ -12,7 +12,7 @@ virtual bool getNextFrame(cv::Mat&)=0; virtual unsigned int getNbFrames() = 0; virtual bool isOpen() const = 0; - virtual void setFrameNumber(const int& frameNumber) = 0; + virtual void setFrameNumber(const unsigned int& frameNumber) = 0; virtual const cv::Size& getSize() const = 0; };
--- a/include/InputVideoFileModule.h Mon Jul 29 18:06:55 2013 -0400 +++ b/include/InputVideoFileModule.h Mon Jul 29 18:58:05 2013 -0400 @@ -18,7 +18,7 @@ bool isOpen() const { return mInit;} - void setFrameNumber(const int& frameNumber); + void setFrameNumber(const unsigned int& frameNumber); const cv::Size& getSize() const { return mSize;}