Mercurial > hg > nsaunier > traffic-intelligence
comparison c/InputFrameListModule.cpp @ 614:5e09583275a4
Merged Nicolas/trafficintelligence into default
| author | Mohamed Gomaa <eng.m.gom3a@gmail.com> |
|---|---|
| date | Fri, 05 Dec 2014 12:13:53 -0500 |
| parents | b829ebdc18e6 |
| children |
comparison
equal
deleted
inserted
replaced
| 598:11f96bd08552 | 614:5e09583275a4 |
|---|---|
| 1 #include "InputFrameListModule.h" | |
| 2 #include "utils.hpp" | |
| 3 | |
| 4 #include <fstream> | |
| 5 #include <ostream> | |
| 6 #include <iostream> | |
| 7 #include <algorithm> | |
| 8 | |
| 9 //#include <boost/algorithm/string.hpp> | |
| 10 #include <boost/filesystem.hpp> | |
| 11 | |
| 12 #include "opencv2/core/core.hpp" | |
| 13 #include "opencv2/highgui/highgui.hpp" | |
| 14 | |
| 15 namespace fs = boost::filesystem; | |
| 16 | |
| 17 InputFrameListModule::InputFrameListModule(const std::string& _dirname) | |
| 18 : mCurrentIdx(0), mInit(false), dirname(_dirname){ | |
| 19 loadImageList(); | |
| 20 } | |
| 21 | |
| 22 InputFrameListModule::~InputFrameListModule(void) { } | |
| 23 | |
| 24 | |
| 25 void InputFrameListModule::setFrameNumber(const unsigned int& frameNumber) { | |
| 26 if (frameNumber < filenames.size()) | |
| 27 mCurrentIdx = frameNumber; | |
| 28 else | |
| 29 mCurrentIdx = filenames.size()-1; | |
| 30 } | |
| 31 | |
| 32 bool InputFrameListModule::getNextFrame(cv::Mat& mat) | |
| 33 { | |
| 34 bool success = false; | |
| 35 if(mCurrentIdx < filenames.size()) { | |
| 36 mat = cv::imread(dirname+filenames[mCurrentIdx++]); | |
| 37 | |
| 38 if(!mat.empty()) | |
| 39 success = true; | |
| 40 } | |
| 41 | |
| 42 return success; | |
| 43 } | |
| 44 | |
| 45 unsigned int InputFrameListModule::getNbFrames(void) { | |
| 46 return filenames.size(); | |
| 47 } | |
| 48 | |
| 49 void InputFrameListModule::loadImageList(void) { | |
| 50 for (fs::directory_iterator iter(dirname); iter!=fs::directory_iterator(); iter++) | |
| 51 filenames.push_back(iter->path().filename().string()); | |
| 52 | |
| 53 sort(filenames.begin(), filenames.end()); | |
| 54 | |
| 55 if(!filenames.empty()) { | |
| 56 std::cout << dirname+filenames[0] << std::endl; | |
| 57 cv::Mat tmpImg = cv::imread(dirname+filenames[0]); | |
| 58 mSize = cv::Size(tmpImg.cols, tmpImg.rows); | |
| 59 mInit = true; | |
| 60 } | |
| 61 } |
