-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcess.cpp
More file actions
186 lines (141 loc) · 4.14 KB
/
Copy pathProcess.cpp
File metadata and controls
186 lines (141 loc) · 4.14 KB
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#include "Process.h"
Process::Process()
{
}
Process::~Process()
{
}
void Process::setTrainingFiles()
{
//get the images ROOT folder
tinydir_dir training_directory_root;
tinydir_open(&training_directory_root, "Sample Digits Train");
// go over all folder inside Sample Digits root folder
while (training_directory_root.has_next)
{
/*
tinydir_file file;
tinydir_readfile(&training_directory_root, &file);
string numbersDirName = file.name;
cout << numbersDirName << endl;
*/
// get the subfolder of root
tinydir_file file;
tinydir_readfile(&training_directory_root, &file);
// if it is a directory
if (file.is_dir)
{
string numbersDirName = file.name;
// skip . / .. /
if (numbersDirName != "." && numbersDirName != "..")
{
//convert the subfolder name to integer
int currentNumberLabel = atoi(file.name);
// prepend full training_files directory
numbersDirName.insert(0, "Sample Digits Train/");
//open the subfolder of Sample Digits
tinydir_dir training_number_subdir;
tinydir_open(&training_number_subdir, numbersDirName.c_str());
//iterate inside subfolders
while (training_number_subdir.has_next)
{
//get the image file
tinydir_file trainingImageFile;
tinydir_readfile(&training_number_subdir, &trainingImageFile);
string trainingImageFileName = trainingImageFile.name;
// // skip . / .. /
if (trainingImageFileName != "." && trainingImageFileName != "..")
{
// prepend full training_files directory
trainingImageFileName.insert(0, numbersDirName + "/");
// store training filename and label
trainingFileNames.push_back(trainingImageFileName);
matrixLabels.push_back(currentNumberLabel);
}
//go into next subdirectory folder
tinydir_next(&training_number_subdir);
}
tinydir_close(&training_number_subdir);
}
}
// get next subfolder 0 , 1 etc
tinydir_next(&training_directory_root);
}
// close directory
tinydir_close(&training_directory_root);
}
void Process::setTestFiles()
{
//get the images ROOT folder
tinydir_dir test_directory_root;
tinydir_open(&test_directory_root, "Sample Digits Test");
// go over all folder inside Sample Digits root folder
while (test_directory_root.has_next)
{
/*
tinydir_file file;
tinydir_readfile(&training_directory_root, &file);
string numbersDirName = file.name;
cout << numbersDirName << endl;
*/
// get the subfolder of root
tinydir_file file;
tinydir_readfile(&test_directory_root, &file);
// if it is a directory
if (file.is_dir)
{
string numbersDirName = file.name;
// skip . / .. /
if (numbersDirName != "." && numbersDirName != "..")
{
//convert the subfolder name to integer
int currentNumberLabel = atoi(file.name);
// prepend full training_files directory
numbersDirName.insert(0, "Sample Digits Test/");
//open the subfolder of Sample Digits
tinydir_dir test_number_subdir;
tinydir_open(&test_number_subdir, numbersDirName.c_str());
//iterate inside subfolders
while (test_number_subdir.has_next)
{
//get the image file
tinydir_file testImageFile;
tinydir_readfile(&test_number_subdir, &testImageFile);
string testImageFileName = testImageFile.name;
// // skip . / .. /
if (testImageFileName != "." && testImageFileName != "..")
{
// prepend full training_files directory
testImageFileName.insert(0, numbersDirName + "/");
// store training filename and label
testFileNames.push_back(testImageFileName);
testLabels.push_back(currentNumberLabel);
}
//go into next subdirectory folder
tinydir_next(&test_number_subdir);
}
tinydir_close(&test_number_subdir);
}
}
// get next subfolder 0 , 1 etc
tinydir_next(&test_directory_root);
}
// close directory
tinydir_close(&test_directory_root);
}
vector<string> Process::getTrainFileNames()
{
return trainingFileNames;
}
vector<int> Process::getMatrixLabels()
{
return matrixLabels;
}
vector<string> Process::getTestFileNames()
{
return testFileNames;
}
vector<int> Process::getTestMatrixLabels()
{
return testLabels;
}