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