ArmNN
 20.11
ImageCSVFileGenerator.cpp File Reference
#include <Filesystem.hpp>
#include <cxxopts/cxxopts.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 196 of file ImageCSVFileGenerator.cpp.

197 {
198  CommandLineProcessor cmdline;
199  if (!cmdline.ProcessCommandLine(argc, argv))
200  {
201  return -1;
202  }
203 
204  const std::string fileFormat(".raw");
205 
206  const std::string rawDirectory(cmdline.GetInputDirectory());
207  const std::string outputPath(cmdline.GetOutputFileName());
208  const std::string bindingId(cmdline.GetInputBindingId());
209 
210  std::vector<fs::path> rawFiles;
211  for (auto& entry : fs::directory_iterator(rawDirectory))
212  {
213  if (entry.path().extension().c_str() == fileFormat)
214  {
215  rawFiles.push_back(entry.path());
216  }
217  }
218 
219  if (!rawFiles.empty())
220  {
221  unsigned int pass = 0;
222  std::ofstream refinementData;
223  refinementData.open(outputPath, std::ofstream::out);
224  if (refinementData.is_open())
225  {
226  for (auto const& raw : rawFiles)
227  {
228  refinementData << pass << ", " << bindingId << ", " << raw.c_str() << "\n";
229  if (!refinementData)
230  {
231  std::cerr << "Failed to write to output file: " << outputPath << std::endl;
232  continue;
233  }
234  ++pass;
235  }
236  refinementData.close();
237  }
238  else
239  {
240  std::cerr << "Failed to open output file: " << outputPath << std::endl;
241  return -1;
242  }
243  }
244  else
245  {
246  std::cerr << "No matching files with the \".raw\" extension found in the directory: "
247  << rawDirectory << std::endl;
248  return -1;
249  }
250 
251  return 0;
252 }