| 123456789101112131415161718192021222324252627282930313233343536373839 |
- #include "ImageProcessor.h"
- #include <filesystem>
- #include <algorithm>
- #include <iostream>
- namespace fs = std::filesystem;
- std::vector<std::string> ImageProcessor::getImagesInDirectory(const std::string& directory) {
- std::vector<std::string> imagePaths;
-
- try {
- for (const auto& entry : fs::recursive_directory_iterator(directory)) {
- if (fs::is_regular_file(entry) && isImageFile(entry.path().string())) {
- imagePaths.push_back(entry.path().string());
- }
- }
- } catch (const std::exception& e) {
- std::cerr << "Error reading directory: " << e.what() << std::endl;
- }
-
- return imagePaths;
- }
- bool ImageProcessor::isImageFile(const std::string& filename) {
- std::vector<std::string> extensions = {".jpg", ".jpeg", ".png", ".bmp", ".tiff", ".tif"};
- std::string lowerFilename = filename;
- std::transform(lowerFilename.begin(), lowerFilename.end(), lowerFilename.begin(), ::tolower);
-
- for (const auto& ext : extensions) {
- if (lowerFilename.length() >= ext.length() &&
- lowerFilename.substr(lowerFilename.length() - ext.length()) == ext) {
- return true;
- }
- }
-
- return false;
- }
|