# HG changeset patch # User Jean-Philippe Jodoin # Date 1375132365 14400 # Node ID c389fae9689ac5720360d084d35c12b4db71c00e # Parent 3399bd48cb40f01ff729e91aa060af833c42f951 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. diff -r 3399bd48cb40 -r c389fae9689a c/InputFrameListModule.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/c/InputFrameListModule.cpp Mon Jul 29 17:12:45 2013 -0400 @@ -0,0 +1,73 @@ +#include "InputFrameListModule.h" +#include +#include + +#include "opencv2/core/core.hpp" +#include "opencv2/highgui/highgui.hpp" + +InputFrameListModule::InputFrameListModule(const std::string& basePath, const std::string& pictureList) +: mInit(false) +, mBasePath(basePath+"/") +, mCurrentIdx(0) +{ + loadFileList(pictureList); +} +InputFrameListModule::~InputFrameListModule() +{ + +} + + + +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(!mCurrentFrame.empty()) + success = true; + mat = mCurrentFrame; + } + + + return success; +} + + + + + +unsigned int InputFrameListModule::getNbFrames() +{ + return mFileList.size(); +} + +void InputFrameListModule::loadFileList(const std::string& path) +{ + std::ifstream inputFile(mBasePath+path.c_str()); + std::string fileContains; + if (inputFile.is_open()) + { + + 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; + } + } +} \ No newline at end of file diff -r 3399bd48cb40 -r c389fae9689a c/InputVideoFileModule.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/c/InputVideoFileModule.cpp Mon Jul 29 17:12:45 2013 -0400 @@ -0,0 +1,32 @@ +#include "InputVideoFileModule.h" + +InputVideoFileModule::InputVideoFileModule(const std::string& videoPath) +: mInit(false) +, mNumberOfFrame(0) +{ + mInit = mVideoCapture.open(videoPath.c_str()); + double frameCount; + frameCount = mVideoCapture.get(CV_CAP_PROP_FRAME_COUNT); + mSize = cv::Size(mVideoCapture.get(CV_CAP_PROP_FRAME_WIDTH), mVideoCapture.get(CV_CAP_PROP_FRAME_HEIGHT)); + mNumberOfFrame = (unsigned int)frameCount; +} + +InputVideoFileModule::~InputVideoFileModule(void) +{ + +} + + + + +bool InputVideoFileModule::getNextFrame(cv::Mat& outputPicture) +{ + bool success = false; + if(mInit) + { + mVideoCapture >> outputPicture; + success = !outputPicture.empty(); + } + return success; +} + diff -r 3399bd48cb40 -r c389fae9689a c/Parameters.cpp --- a/c/Parameters.cpp Mon Jul 29 13:46:07 2013 -0400 +++ b/c/Parameters.cpp Mon Jul 29 17:12:45 2013 -0400 @@ -35,6 +35,8 @@ ("video-fps", po::value(&videoFPS), "original video frame rate") ("frame1", po::value(&frame1), "first frame to process") ("nframes", po::value(&nFrames), "number of frame to process") + ("list-filename", po::value(&listFilename), "filename of the list of image files") + ("folder-data", po::value(&folderData), "folder where video or list file is placed") // feature tracking ("max-nfeatures", po::value(&maxNFeatures), "maximum number of features added at each frame") ("feature-quality", po::value(&featureQuality), "quality level of the good features to track") diff -r 3399bd48cb40 -r c389fae9689a c/feature-based-tracking.cpp --- 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 #include +#include "InputVideoFileModule.h" +#include "InputFrameListModule.h" + + #include #include #include @@ -78,28 +82,27 @@ // BruteForceMatcher descMatcher; // vector 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) { diff -r 3399bd48cb40 -r c389fae9689a c/utils.cpp --- a/c/utils.cpp Mon Jul 29 13:46:07 2013 -0400 +++ b/c/utils.cpp Mon Jul 29 17:12:45 2013 -0400 @@ -41,7 +41,7 @@ getline(f, s); } - if (s[0] == ::commentChar) + if (!s.empty() && s[0] == ::commentChar) s.clear(); return s; } diff -r 3399bd48cb40 -r c389fae9689a include/InputFrameListModule.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/InputFrameListModule.h Mon Jul 29 17:12:45 2013 -0400 @@ -0,0 +1,41 @@ +#ifndef INPUT_FRAME_LIST_MODULE_H +#define INPUT_FRAME_LIST_MODULE_H + +#include "InputFrameProviderIface.h" +#include +#include + +class InputFrameListModule : public InputFrameProviderIface +{ +public: + InputFrameListModule(const std::string& basePath,const std::string& pictureList); + ~InputFrameListModule(); + + + + bool getNextFrame(cv::Mat&); + unsigned int getNbFrames(); + bool isOpen() const { return mInit;} + + + + + + + + + + + virtual const cv::Size& getSize() const { return mSize;} +private: + void loadFileList(const std::string& path); + std::vector mFileList; + int mCurrentIdx; + bool mInit; + std::string mBasePath; + cv::Mat mCurrentFrame; + cv::Size mSize; + +}; + +#endif \ No newline at end of file diff -r 3399bd48cb40 -r c389fae9689a include/InputFrameProviderIface.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/InputFrameProviderIface.h Mon Jul 29 17:12:45 2013 -0400 @@ -0,0 +1,23 @@ +#ifndef INPUT_FRAME_PROVIDER_IFACE_H +#define INPUT_FRAME_PROVIDER_IFACE_H + +#include "opencv2/core/core.hpp" +#include + + +class InputFrameProviderIface +{ +public: + + virtual ~InputFrameProviderIface(){} + virtual bool getNextFrame(cv::Mat&)=0; + virtual unsigned int getNbFrames() = 0; + virtual bool isOpen() const = 0; + virtual const cv::Size& getSize() const = 0; + + + +}; + + +#endif \ No newline at end of file diff -r 3399bd48cb40 -r c389fae9689a include/InputVideoFileModule.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/InputVideoFileModule.h Mon Jul 29 17:12:45 2013 -0400 @@ -0,0 +1,37 @@ +#ifndef INPUT_VIDEO_FILE_MODULE_H +#define INPUT_VIDEO_FILE_MODULE_H + +#include "InputFrameProviderIface.h" +#include +#include "opencv2/core/core.hpp" +#include "opencv2/highgui/highgui.hpp" + +class InputVideoFileModule : public InputFrameProviderIface +{ +public: + InputVideoFileModule(const std::string& videoPath); + ~InputVideoFileModule(); + + + bool isOpen() const { return mInit;} + const cv::Size& getSize() const { return mSize;} + + + + + + bool getNextFrame(cv::Mat&); + + unsigned int getNbFrames(){ return mNumberOfFrame;} + + + + +private: + cv::Size mSize; + cv::VideoCapture mVideoCapture; + bool mInit; + int mNumberOfFrame; +}; + +#endif \ No newline at end of file diff -r 3399bd48cb40 -r c389fae9689a include/Motion.hpp --- a/include/Motion.hpp Mon Jul 29 13:46:07 2013 -0400 +++ b/include/Motion.hpp Mon Jul 29 17:12:45 2013 -0400 @@ -5,6 +5,7 @@ #include #include + template class TrajectoryDBAccess; template class TrajectoryDBAccessList; @@ -13,7 +14,8 @@ /** Class for feature data positions, velocities and other statistics to evaluate their quality before saving. */ -class FeatureTrajectory { +class FeatureTrajectory +{ public: FeatureTrajectory(const unsigned int& frameNum, const cv::Point2f& p, const cv::Mat& homography); @@ -75,10 +77,12 @@ typedef boost::shared_ptr FeatureTrajectoryPtr; // inlined -inline std::ostream& operator<<(std::ostream& out, const FeatureTrajectory& ft) { +inline std::ostream& operator<<(std::ostream& out, const FeatureTrajectory& ft) +{ out << *(ft.positions); out << "\n"; out << *(ft.velocities); + return out; } diff -r 3399bd48cb40 -r c389fae9689a include/Parameters.hpp --- a/include/Parameters.hpp Mon Jul 29 13:46:07 2013 -0400 +++ b/include/Parameters.hpp Mon Jul 29 17:12:45 2013 -0400 @@ -17,6 +17,11 @@ bool groupFeatures; std::string videoFilename; + + std::string listFilename; + std::string folderData; + + std::string databaseFilename; std::string homographyFilename; std::string maskFilename; diff -r 3399bd48cb40 -r c389fae9689a trafficintelligence.vcxproj --- a/trafficintelligence.vcxproj Mon Jul 29 13:46:07 2013 -0400 +++ b/trafficintelligence.vcxproj Mon Jul 29 17:12:45 2013 -0400 @@ -14,6 +14,8 @@ + + @@ -21,6 +23,9 @@ + + +