Mercurial > hg > nsaunier > traffic-intelligence
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 399:c389fae9689a | 400:7ef1071e3cc3 |
|---|---|
| 1 #include "InputFrameListModule.h" | 1 #include "InputFrameListModule.h" |
| 2 #include "utils.hpp" | |
| 3 | |
| 2 #include <fstream> | 4 #include <fstream> |
| 3 #include <ostream> | 5 #include <ostream> |
| 6 #include <iostream> | |
| 4 | 7 |
| 5 #include "opencv2/core/core.hpp" | 8 #include "opencv2/core/core.hpp" |
| 6 #include "opencv2/highgui/highgui.hpp" | 9 #include "opencv2/highgui/highgui.hpp" |
| 7 | 10 |
| 8 InputFrameListModule::InputFrameListModule(const std::string& basePath, const std::string& pictureList) | 11 InputFrameListModule::InputFrameListModule(const std::string& basePath, const std::string& pictureList) |
| 9 : mInit(false) | 12 : mCurrentIdx(0), mInit(false), mBasePath(basePath+"/") { |
| 10 , mBasePath(basePath+"/") | 13 loadFileList(pictureList); |
| 11 , mCurrentIdx(0) | |
| 12 { | |
| 13 loadFileList(pictureList); | |
| 14 } | 14 } |
| 15 InputFrameListModule::~InputFrameListModule() | 15 InputFrameListModule::~InputFrameListModule() |
| 16 { | 16 { |
| 17 | 17 |
| 18 } | 18 } |
| 19 | 19 |
| 20 | 20 |
| 21 | 21 |
| 22 bool InputFrameListModule::getNextFrame(cv::Mat& mat) | 22 bool InputFrameListModule::getNextFrame(cv::Mat& mat) |
| 23 { | 23 { |
| 24 bool success = false; | 24 bool success = false; |
| 25 if(mCurrentIdx < mFileList.size()) | 25 if(mCurrentIdx < mFileList.size()) |
| 26 { | 26 { |
| 27 const std::string& fileName = mBasePath+mFileList[mCurrentIdx++]; | 27 const std::string& fileName = mBasePath+mFileList[mCurrentIdx++]; |
| 28 mCurrentFrame = cv::imread(fileName); | 28 mCurrentFrame = cv::imread(fileName); |
| 29 | 29 |
| 30 if(!mCurrentFrame.empty()) | 30 if(!mCurrentFrame.empty()) |
| 31 success = true; | 31 success = true; |
| 32 mat = mCurrentFrame; | 32 mat = mCurrentFrame; |
| 33 } | 33 } |
| 34 | 34 |
| 35 | 35 |
| 36 return success; | 36 return success; |
| 37 } | 37 } |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | 38 |
| 43 unsigned int InputFrameListModule::getNbFrames() | 39 unsigned int InputFrameListModule::getNbFrames() |
| 44 { | 40 { |
| 45 return mFileList.size(); | 41 return mFileList.size(); |
| 46 } | 42 } |
| 47 | 43 |
| 48 void InputFrameListModule::loadFileList(const std::string& path) | 44 void InputFrameListModule::loadFileList(const std::string& path) |
| 49 { | 45 { |
| 50 std::ifstream inputFile(mBasePath+path.c_str()); | 46 std::ifstream inputFile((mBasePath+path).c_str()); |
| 51 std::string fileContains; | 47 ::openCheck(inputFile, mBasePath+path, "InputFrameListModule::loadFileList"); |
| 52 if (inputFile.is_open()) | 48 std::string str; |
| 53 { | 49 while( !inputFile.eof() ) |
| 54 | 50 { |
| 55 std::string str; | 51 std::getline(inputFile, str); |
| 56 while( !inputFile.eof() ) | 52 if (str.empty()) |
| 57 { | 53 break; |
| 58 std::getline(inputFile, str); | 54 if (str.at(0) == '#' ) |
| 59 if (str.empty()) | 55 continue; /* comment */ |
| 60 break; | 56 mFileList.push_back(str); |
| 61 if (str.at(0) == '#' ) | 57 } |
| 62 continue; /* comment */ | |
| 63 mFileList.push_back(str); | |
| 64 } | |
| 65 | 58 |
| 66 if(!mFileList.empty()) | 59 if(!mFileList.empty()) |
| 67 { | 60 { |
| 68 cv::Mat tmpImg = cv::imread(mBasePath+mFileList[0]); | 61 cv::Mat tmpImg = cv::imread(mBasePath+mFileList[0]); |
| 69 mSize = cv::Size(tmpImg.cols, tmpImg.rows); | 62 mSize = cv::Size(tmpImg.cols, tmpImg.rows); |
| 70 mInit = true; | 63 mInit = true; |
| 71 } | 64 } |
| 72 } | |
| 73 } | 65 } |
