Mercurial Hosting > traffic-intelligence
diff c/InputFrameListModule.cpp @ 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 |
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; + } +}