From efe79db062a99273c39acd4b7a1429a75417e35c Mon Sep 17 00:00:00 2001 From: Matt Hill Date: Mon, 19 May 2014 22:51:15 -0500 Subject: [PATCH] Case insensitive file match for alpr (matches .jpg and .JPEG) --- src/main.cpp | 9 +++++---- src/openalpr/support/filesystem.cpp | 13 +++++++++++++ src/openalpr/support/filesystem.h | 2 ++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index e6c9ff3..bfee3e3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -197,8 +197,8 @@ int main( int argc, const char** argv ) std::cout << "Video processing ended" << std::endl; } - else if (hasEnding(filename, ".avi") || hasEnding(filename, ".mp4") || hasEnding(filename, ".webm") || - hasEnding(filename, ".flv") || hasEnding(filename, ".mjpg") || hasEnding(filename, ".mjpeg")) + else if (hasEndingInsensitive(filename, ".avi") || hasEndingInsensitive(filename, ".mp4") || hasEndingInsensitive(filename, ".webm") || + hasEndingInsensitive(filename, ".flv") || hasEndingInsensitive(filename, ".mjpg") || hasEndingInsensitive(filename, ".mjpeg")) { if (fileExists(filename.c_str())) { @@ -227,7 +227,8 @@ int main( int argc, const char** argv ) std::cerr << "Video file not found: " << filename << std::endl; } } - else if (hasEnding(filename, ".png") || hasEnding(filename, ".jpg") || hasEnding(filename, ".gif")) + else if (hasEndingInsensitive(filename, ".png") || hasEndingInsensitive(filename, ".jpg") || + hasEndingInsensitive(filename, ".jpeg") || hasEndingInsensitive(filename, ".gif")) { if (fileExists(filename.c_str())) { @@ -248,7 +249,7 @@ int main( int argc, const char** argv ) for (int i = 0; i< files.size(); i++) { - if (hasEnding(files[i], ".jpg") || hasEnding(files[i], ".png")) + if (hasEndingInsensitive(files[i], ".jpg") || hasEndingInsensitive(files[i], ".png")) { std::string fullpath = filename + "/" + files[i]; std::cout << fullpath << std::endl; diff --git a/src/openalpr/support/filesystem.cpp b/src/openalpr/support/filesystem.cpp index 957750b..7e8d66e 100644 --- a/src/openalpr/support/filesystem.cpp +++ b/src/openalpr/support/filesystem.cpp @@ -21,6 +21,19 @@ bool hasEnding (std::string const &fullString, std::string const &ending) } } +bool hasEndingInsensitive(const std::string& fullString, const std::string& ending) +{ + if (fullString.length() < ending.length()) + return false; + + int startidx = fullString.length() - ending.length(); + + for (unsigned int i = startidx; i < fullString.length(); ++i) + if (tolower(fullString[i]) != tolower(ending[i - startidx])) + return false; + return true; +} + bool DirectoryExists( const char* pzPath ) { if ( pzPath == NULL) return false; diff --git a/src/openalpr/support/filesystem.h b/src/openalpr/support/filesystem.h index e0d1372..45d22d3 100644 --- a/src/openalpr/support/filesystem.h +++ b/src/openalpr/support/filesystem.h @@ -19,6 +19,8 @@ bool startsWith(std::string const &fullString, std::string const &prefix); bool hasEnding (std::string const &fullString, std::string const &ending); +bool hasEndingInsensitive(const std::string& fullString, const std::string& ending); + bool DirectoryExists( const char* pzPath ); bool fileExists( const char* pzPath ); std::vector getFilesInDir(const char* dirPath);