ImageProcessor.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include "ImageProcessor.h"
  2. #include <filesystem>
  3. #include <algorithm>
  4. #include <iostream>
  5. namespace fs = std::filesystem;
  6. std::vector<std::string> ImageProcessor::getImagesInDirectory(const std::string& directory) {
  7. std::vector<std::string> imagePaths;
  8. try {
  9. for (const auto& entry : fs::recursive_directory_iterator(directory)) {
  10. if (fs::is_regular_file(entry) && isImageFile(entry.path().string())) {
  11. imagePaths.push_back(entry.path().string());
  12. }
  13. }
  14. } catch (const std::exception& e) {
  15. std::cerr << "Error reading directory: " << e.what() << std::endl;
  16. }
  17. return imagePaths;
  18. }
  19. bool ImageProcessor::isImageFile(const std::string& filename) {
  20. std::vector<std::string> extensions = {".jpg", ".jpeg", ".png", ".bmp", ".tiff", ".tif"};
  21. std::string lowerFilename = filename;
  22. std::transform(lowerFilename.begin(), lowerFilename.end(), lowerFilename.begin(), ::tolower);
  23. for (const auto& ext : extensions) {
  24. if (lowerFilename.length() >= ext.length() &&
  25. lowerFilename.substr(lowerFilename.length() - ext.length()) == ext) {
  26. return true;
  27. }
  28. }
  29. return false;
  30. }