-
Notifications
You must be signed in to change notification settings - Fork 0
/
io.cpp
49 lines (38 loc) · 1.08 KB
/
io.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "io.hpp"
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/filesystem.hpp>
#include <boost/algorithm/string.hpp>
using namespace std;
ImageReader::ImageReader(string imageDir)
{
directory = imageDir;
namespace fs = boost::filesystem;
fs::path imgDir(imageDir);
fs::directory_iterator end_iter;
list<string> imgNames;
if (fs::exists(imgDir) && fs::is_directory(imgDir))
{
for(fs::directory_iterator dir_iter(imgDir); dir_iter != end_iter; dir_iter++)
{
if (boost::algorithm::iequals(fs::extension(dir_iter->path()), ".ppm"))
{
string path = dir_iter->path().string();
imgNames.push_back(path);
}
}
imgNames.sort();
}
imageNames.insert(imageNames.begin(), imgNames.begin(), imgNames.end());
numImages = imageNames.size();
currImgIndex = 0;
}
cv::Mat ImageReader::getNextImage()
{
//string imageName = directory + "frame" + boost::lexical_cast<string>(currImgIndex) + ".ppm";
string imageName = imageNames[currImgIndex];
currImgIndex++;
printf("%s\n",imageName.c_str());
return cv::imread(imageName);
}