Mercurial Hosting > traffic-intelligence
view c/InputFrameListModule.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 | |
children | 7ef1071e3cc3 |
line wrap: on
line source
#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; } } }