From a10d4e8cbae5246eadea684d1222beef44a51bc9 Mon Sep 17 00:00:00 2001 From: gineshidalgo99 Date: Tue, 1 Aug 2017 00:58:41 -1000 Subject: [PATCH] Valid image extensions are now case insensitive --- include/openpose/utilities/string.hpp | 4 +++ .../producer/imageDirectoryReader.cpp | 4 +-- src/openpose/utilities/fileSystem.cpp | 5 +-- src/openpose/utilities/string.cpp | 31 +++++++++++++++++++ 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/include/openpose/utilities/string.hpp b/include/openpose/utilities/string.hpp index 596329cc..16df3134 100644 --- a/include/openpose/utilities/string.hpp +++ b/include/openpose/utilities/string.hpp @@ -16,6 +16,10 @@ namespace op OP_API std::string toFixedLengthString(const T number, const unsigned long long stringLength = 0); OP_API std::vector splitString(const std::string& stringToSplit, const std::string& delimiter); + + OP_API std::string toLower(const std::string& string); + + OP_API std::string toUpper(const std::string& string); } #endif // OPENPOSE_UTILITIES_STRING_HPP diff --git a/src/openpose/producer/imageDirectoryReader.cpp b/src/openpose/producer/imageDirectoryReader.cpp index bf5cd5ff..12df26f4 100644 --- a/src/openpose/producer/imageDirectoryReader.cpp +++ b/src/openpose/producer/imageDirectoryReader.cpp @@ -10,8 +10,8 @@ namespace op try { // Get files on directory with the desired extensions - const std::vector extensions{".bmp", ".dib", ".pbm", ".pgm", ".ppm", ".sr", ".ras", // Completely supported by OpenCV - ".jpg", "jpeg", ".png"}; // Most of them supported by OpenCV + const std::vector extensions{"bmp", "dib", "pbm", "pgm", "ppm", "sr", "ras", // Completely supported by OpenCV + "jpg", "jpeg", "png"}; // Most of them supported by OpenCV const auto imagePaths = getFilesOnDirectory(imageDirectoryPath, extensions); // Check #files > 0 diff --git a/src/openpose/utilities/fileSystem.cpp b/src/openpose/utilities/fileSystem.cpp index 3cc87f5f..67a02ba3 100644 --- a/src/openpose/utilities/fileSystem.cpp +++ b/src/openpose/utilities/fileSystem.cpp @@ -1,6 +1,7 @@ #include #include #include +#include namespace op { @@ -134,9 +135,9 @@ namespace op { try { - const auto cleanedExtension = removeExtensionDot(extension); + const auto cleanedExtension = toLower(removeExtensionDot(extension)); for (auto& extensionI : extensions) - if (cleanedExtension == removeExtensionDot(extensionI)) + if (cleanedExtension == toLower(removeExtensionDot(extensionI))) return true; return false; } diff --git a/src/openpose/utilities/string.cpp b/src/openpose/utilities/string.cpp index 31613c2e..a15857b0 100644 --- a/src/openpose/utilities/string.cpp +++ b/src/openpose/utilities/string.cpp @@ -1,3 +1,4 @@ +#include // std::transform #include namespace op @@ -55,6 +56,36 @@ namespace op } } + std::string toLower(const std::string& string) + { + try + { + auto result = string; + std::transform(string.begin(), string.end(), result.begin(), tolower); + return result; + } + catch (const std::exception& e) + { + error(e.what(), __LINE__, __FUNCTION__, __FILE__); + return ""; + } + } + + std::string toUpper(const std::string& string) + { + try + { + auto result = string; + std::transform(string.begin(), string.end(), result.begin(), toupper); + return result; + } + catch (const std::exception& e) + { + error(e.what(), __LINE__, __FUNCTION__, __FILE__); + return ""; + } + } + // Signed template std::string toFixedLengthString(const char number, const unsigned long long stringLength);