diff c/InputFrameListModule.cpp @ 401:b829ebdc18e6

simplified input of directories of video frames (simply use the video filename parameter to point at the directory)
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Mon, 29 Jul 2013 18:58:05 -0400
parents 7ef1071e3cc3
children
line wrap: on
line diff
--- a/c/InputFrameListModule.cpp	Mon Jul 29 18:06:55 2013 -0400
+++ b/c/InputFrameListModule.cpp	Mon Jul 29 18:58:05 2013 -0400
@@ -4,62 +4,58 @@
 #include <fstream>
 #include <ostream>
 #include <iostream>
+#include <algorithm>
+
+//#include <boost/algorithm/string.hpp>
+#include <boost/filesystem.hpp>
 
 #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()
-{
+namespace fs = boost::filesystem;
 
+InputFrameListModule::InputFrameListModule(const std::string& _dirname)
+  : mCurrentIdx(0), mInit(false), dirname(_dirname){
+  loadImageList();
 }
 
+InputFrameListModule::~InputFrameListModule(void) { }
 
 
+void InputFrameListModule::setFrameNumber(const unsigned int& frameNumber) {
+  if (frameNumber < filenames.size())
+    mCurrentIdx = frameNumber;
+  else
+    mCurrentIdx = filenames.size()-1;
+}
+
 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(mCurrentIdx < filenames.size()) {
+      mat = cv::imread(dirname+filenames[mCurrentIdx++]);
 
-      if(!mCurrentFrame.empty())
+      if(!mat.empty())
 	success = true;
-      mat = mCurrentFrame;
     }
-
 	
   return success;
 }
 
-unsigned int InputFrameListModule::getNbFrames()
-{
-  return mFileList.size();
+unsigned int InputFrameListModule::getNbFrames(void) {
+  return filenames.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;
-    }
+void InputFrameListModule::loadImageList(void) {
+  for (fs::directory_iterator iter(dirname); iter!=fs::directory_iterator(); iter++)
+    filenames.push_back(iter->path().filename().string());
+
+  sort(filenames.begin(), filenames.end());
+
+  if(!filenames.empty()) {
+    std::cout << dirname+filenames[0] << std::endl;
+    cv::Mat tmpImg = cv::imread(dirname+filenames[0]);
+    mSize = cv::Size(tmpImg.cols, tmpImg.rows);
+    mInit = true;
+  }
 }