-
Notifications
You must be signed in to change notification settings - Fork 3
/
imagemanager.cpp
executable file
·171 lines (145 loc) · 4.23 KB
/
imagemanager.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
* IMBS-MT Background Subtraction Library multi-thread
* Copyright 2016 Domenico Daniele Bloisi
*
* This file is part of IMBS and it is distributed under the terms of the
* GNU Lesser General Public License (Lesser GPL)
*
*
*
* IMBS-MT is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* IMBS-MT is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with IMBS-MT. If not, see <http://www.gnu.org/licenses/>.
*
* This file contains the C++ OpenCV based implementation for
* IMBS-MT algorithm described in
*
* Domenico D. Bloisi, Andrea Pennisi, and Luca Iocchi
* "Parallel Multi-modal Background Modeling"
* Pattern Recognition Letters
*
* Please, cite the above paper if you use IMBS-MT.
*
* IMBS-MT has been written by Domenico D. Bloisi and Andrea Pennisi
*
* Please, report suggestions/comments/bugs to
*
*/
#include "imagemanager.h"
#include "natural_less.h"
#include <assert.h>
#if defined(_MSC_VER)
#include <windows.h>
#endif
ImageManager::ImageManager(const std::string &d)
{
dir_name = d;
#if defined(_MSC_VER)
WIN32_FIND_DATA ffd;
LARGE_INTEGER filesize;
TCHAR szDir[MAX_PATH];
size_t length_of_arg;
HANDLE hFind = INVALID_HANDLE_VALUE;
DWORD dwError = 0;
// Check that the input path plus 3 is not longer than MAX_PATH.
// Three characters are for the "\*" plus NULL appended below.
StringCchLength(dir_name.c_str(), MAX_PATH, &length_of_arg);
if (length_of_arg > (MAX_PATH - 3))
{
_tprintf(TEXT("\nDirectory path is too long.\n"));
exit(EXIT_FAILURE);
}
_tprintf(TEXT("\nTarget directory is %s\n\n"), dir_name.c_str());
// Prepare string for use with FindFile functions. First, copy the
// string to a buffer, then append '\*' to the directory name.
StringCchCopy(szDir, MAX_PATH, dir_name.c_str());
StringCchCat(szDir, MAX_PATH, TEXT("\\*"));
// Find the first file in the directory.
hFind = FindFirstFile(szDir, &ffd);
if (INVALID_HANDLE_VALUE == hFind)
{
exit(EXIT_FAILURE);
}
// List all the files in the directory with some info about them.
do
{
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
continue;
}
else
{
PTSTR pszFileName = ffd.cFileName;
std::string n(pszFileName);
filename.push_back(dir_name + "\\" + n);
}
}
while (FindNextFile(hFind, &ffd) != 0);
dwError = GetLastError();
if (dwError != ERROR_NO_MORE_FILES)
{
exit(EXIT_FAILURE);
}
FindClose(hFind);
#elif defined(__GNUC__) || defined(__GNUG__)
DIR *dir;
try
{
dir = opendir(d.c_str());
} catch (std::exception& e)
{
std::cout << "Directory does not exist " << e.what() << std::endl;
exit(EXIT_FAILURE);
}
struct dirent *dp;
while ((dp=readdir(dir)) != NULL) {
if(strcmp(dp->d_name, "..") != 0 && strcmp(dp->d_name, ".") != 0 && dp->d_name[0] != '.'
&& dp->d_name[0] != '~') {
filename.push_back(dir_name + "/" + std::string(dp->d_name));
}
}
#endif
assert(filename.size() != 0);
sorting(filename);
count = -1;
end = filename.size();
}
ImageManager::~ImageManager() {
filename.clear();
}
void ImageManager::sorting(std::vector<std::string>& data)
{
std::sort(data.begin(), data.end(), natural_sort);
}
std::string ImageManager::next(const int &speed) {
if(count + speed >= end - 1)
{
count = end - 1;
}
else
{
count += speed;
}
return filename[count];
}
std::string ImageManager::prev(const int &speed) {
if(count - speed >= 0)
{
count -= speed;
}
else
{
count = 0;
}
return filename[count];
}