view 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
line wrap: on
line source

#include "InputFrameListModule.h"
#include "utils.hpp"

#include <fstream>
#include <ostream>
#include <iostream>

#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()
{

}



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());
  ::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;
    }
}