Mercurial Hosting > traffic-intelligence
changeset 400:7ef1071e3cc3
clean up of input classes for list of images and video files
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Mon, 29 Jul 2013 18:06:55 -0400 |
parents | c389fae9689a |
children | b829ebdc18e6 |
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, 190 insertions(+), 217 deletions(-) [+] |
line wrap: on
line diff
--- a/c/InputFrameListModule.cpp Mon Jul 29 17:12:45 2013 -0400 +++ b/c/InputFrameListModule.cpp Mon Jul 29 18:06:55 2013 -0400 @@ -1,73 +1,65 @@ -#include "InputFrameListModule.h" -#include <fstream> -#include <ostream> - -#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 +#include "InputFrameListModule.h" +#include "utils.hpp" + +#include <fstream> +#include <ostream> +#include <iostream> + +#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() +{ + +} + + + +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()); + ::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; + } +}
--- a/c/InputVideoFileModule.cpp Mon Jul 29 17:12:45 2013 -0400 +++ b/c/InputVideoFileModule.cpp Mon Jul 29 18:06:55 2013 -0400 @@ -1,32 +1,31 @@ -#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; -} - +#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) { } + + +void InputVideoFileModule::setFrameNumber(const int& frameNumber) { + mVideoCapture.set(CV_CAP_PROP_POS_FRAMES, frameNumber); +} + +bool InputVideoFileModule::getNextFrame(cv::Mat& outputPicture) +{ + bool success = false; + if(mInit) + { + mVideoCapture >> outputPicture; + success = !outputPicture.empty(); + } + return success; +} +
--- a/c/Makefile Mon Jul 29 17:12:45 2013 -0400 +++ b/c/Makefile Mon Jul 29 18:06:55 2013 -0400 @@ -49,7 +49,7 @@ CXXFLAGS = $(INCLUDE) $(CFLAGS) #GUI_OBJS = -CV_OBJS = cvutils.o +CV_OBJS = cvutils.o InputFrameListModule.o InputVideoFileModule.o COMMON_OBJS = utils.o Motion.o Parameters.o utils.o OBJS = $(COMMON_OBJS) $(CV_OBJS) TESTS_OBJS = test_feature.o test_graph.o
--- a/c/feature-based-tracking.cpp Mon Jul 29 17:12:45 2013 -0400 +++ b/c/feature-based-tracking.cpp Mon Jul 29 18:06:55 2013 -0400 @@ -82,18 +82,17 @@ // BruteForceMatcher<Hamming> descMatcher; // vector<DMatch> matches; - InputFrameProviderIface* capture = nullptr; + InputFrameProviderIface* capture = 0; if(!params.listFilename.empty() && !params.folderData.empty()) - capture = new InputFrameListModule(params.folderData, params.listFilename); + capture = new InputFrameListModule(params.folderData, params.listFilename); else if(!params.videoFilename.empty()) - capture = new InputVideoFileModule(params.videoFilename); + 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); + cout << "No valid input parameters"; + + if(!capture->isOpen()) { + cout << "Video filename " << params.videoFilename << " could not be opened. Exiting." << endl; + exit(0); } Size videoSize = capture->getSize(); @@ -136,7 +135,7 @@ if (params.nFrames > 0) lastFrameNum = MIN(params.frame1+static_cast<unsigned int>(params.nFrames), nFrames); - //capture.set(CV_CAP_PROP_POS_FRAMES, params.frame1); + capture->setFrameNumber(params.frame1); for (unsigned int frameNum = params.frame1; (frameNum < lastFrameNum) && !::interruptionKey(key); frameNum++) { bool success = capture->getNextFrame(frame);
--- a/include/InputFrameListModule.h Mon Jul 29 17:12:45 2013 -0400 +++ b/include/InputFrameListModule.h Mon Jul 29 18:06:55 2013 -0400 @@ -1,41 +1,33 @@ -#ifndef INPUT_FRAME_LIST_MODULE_H -#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(); - - - - 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<std::string> mFileList; - int mCurrentIdx; - bool mInit; - std::string mBasePath; - cv::Mat mCurrentFrame; - cv::Size mSize; - -}; - -#endif \ No newline at end of file +#ifndef INPUT_FRAME_LIST_MODULE_H +#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(); + + + + bool getNextFrame(cv::Mat&); + unsigned int getNbFrames(); + bool isOpen() const { return mInit;} + void setFrameNumber(const int& frameNumber) {} // does nothing for now + + virtual const cv::Size& getSize() const { return mSize;} + private: + void loadFileList(const std::string& path); + std::vector<std::string> mFileList; + unsigned int mCurrentIdx; + bool mInit; + std::string mBasePath; + cv::Mat mCurrentFrame; + cv::Size mSize; + +}; + +#endif
--- a/include/InputFrameProviderIface.h Mon Jul 29 17:12:45 2013 -0400 +++ b/include/InputFrameProviderIface.h Mon Jul 29 18:06:55 2013 -0400 @@ -1,23 +1,19 @@ -#ifndef INPUT_FRAME_PROVIDER_IFACE_H -#define INPUT_FRAME_PROVIDER_IFACE_H - -#include "opencv2/core/core.hpp" -#include <string> - - -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 +#ifndef INPUT_FRAME_PROVIDER_IFACE_H +#define INPUT_FRAME_PROVIDER_IFACE_H + +#include "opencv2/core/core.hpp" +#include <string> + + +class InputFrameProviderIface +{ +public: + virtual ~InputFrameProviderIface(){} + virtual bool getNextFrame(cv::Mat&)=0; + virtual unsigned int getNbFrames() = 0; + virtual bool isOpen() const = 0; + virtual void setFrameNumber(const int& frameNumber) = 0; + virtual const cv::Size& getSize() const = 0; +}; + +#endif
--- a/include/InputVideoFileModule.h Mon Jul 29 17:12:45 2013 -0400 +++ b/include/InputVideoFileModule.h Mon Jul 29 18:06:55 2013 -0400 @@ -1,37 +1,32 @@ -#ifndef INPUT_VIDEO_FILE_MODULE_H -#define INPUT_VIDEO_FILE_MODULE_H - -#include "InputFrameProviderIface.h" -#include <string> -#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 +#ifndef INPUT_VIDEO_FILE_MODULE_H +#define INPUT_VIDEO_FILE_MODULE_H + +#include "InputFrameProviderIface.h" +#include <string> +#include "opencv2/core/core.hpp" +#include "opencv2/highgui/highgui.hpp" + +class InputVideoFileModule : public InputFrameProviderIface +{ +public: + InputVideoFileModule(const std::string& videoPath); + ~InputVideoFileModule(); + + bool getNextFrame(cv::Mat&); + + unsigned int getNbFrames(){ return mNumberOfFrame;} + + bool isOpen() const { return mInit;} + + void setFrameNumber(const int& frameNumber); + + const cv::Size& getSize() const { return mSize;} + +private: + cv::Size mSize; + cv::VideoCapture mVideoCapture; + bool mInit; + int mNumberOfFrame; +}; + +#endif