ArmNN
 20.02
ImageCSVFileGenerator.cpp File Reference
#include <boost/filesystem.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/program_options.hpp>
#include <algorithm>
#include <fstream>
#include <iostream>
#include <string>

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 167 of file ImageCSVFileGenerator.cpp.

168 {
169  CommandLineProcessor cmdline;
170  if (!cmdline.ProcessCommandLine(argc, argv))
171  {
172  return -1;
173  }
174 
175  namespace fs = boost::filesystem;
176 
177  const std::string fileFormat(".raw");
178 
179  const std::string rawDirectory(cmdline.GetInputDirectory());
180  const std::string outputPath(cmdline.GetOutputFileName());
181  const std::string bindingId(cmdline.GetInputBindingId());
182 
183  std::vector<fs::path> rawFiles;
184  for (auto& entry : boost::make_iterator_range(fs::directory_iterator(rawDirectory), {}))
185  {
186  if (entry.path().extension().c_str() == fileFormat)
187  {
188  rawFiles.push_back(entry.path());
189  }
190  }
191 
192  if (!rawFiles.empty())
193  {
194  unsigned int pass = 0;
195  std::ofstream refinementData;
196  refinementData.open(outputPath, std::ofstream::out);
197  if (refinementData.is_open())
198  {
199  for (auto const& raw : rawFiles)
200  {
201  refinementData << pass << ", " << bindingId << ", " << raw.c_str() << "\n";
202  if (!refinementData)
203  {
204  std::cerr << "Failed to write to output file: " << outputPath << std::endl;
205  continue;
206  }
207  ++pass;
208  }
209  refinementData.close();
210  }
211  else
212  {
213  std::cerr << "Failed to open output file: " << outputPath << std::endl;
214  return -1;
215  }
216  }
217  else
218  {
219  std::cerr << "No matching files with the \".raw\" extension found in the directory: "
220  << rawDirectory << std::endl;
221  return -1;
222  }
223 
224  return 0;
225 }