ArmNN
 20.08
ImageCSVFileGenerator.cpp File Reference
#include <Filesystem.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 165 of file ImageCSVFileGenerator.cpp.

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