Case insensitive file match for alpr (matches .jpg and .JPEG)

This commit is contained in:
Matt Hill
2014-05-19 22:51:15 -05:00
parent 765a41685d
commit efe79db062
3 changed files with 20 additions and 4 deletions

View File

@@ -197,8 +197,8 @@ int main( int argc, const char** argv )
std::cout << "Video processing ended" << std::endl; std::cout << "Video processing ended" << std::endl;
} }
else if (hasEnding(filename, ".avi") || hasEnding(filename, ".mp4") || hasEnding(filename, ".webm") || else if (hasEndingInsensitive(filename, ".avi") || hasEndingInsensitive(filename, ".mp4") || hasEndingInsensitive(filename, ".webm") ||
hasEnding(filename, ".flv") || hasEnding(filename, ".mjpg") || hasEnding(filename, ".mjpeg")) hasEndingInsensitive(filename, ".flv") || hasEndingInsensitive(filename, ".mjpg") || hasEndingInsensitive(filename, ".mjpeg"))
{ {
if (fileExists(filename.c_str())) 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; 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())) if (fileExists(filename.c_str()))
{ {
@@ -248,7 +249,7 @@ int main( int argc, const char** argv )
for (int i = 0; i< files.size(); i++) 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::string fullpath = filename + "/" + files[i];
std::cout << fullpath << std::endl; std::cout << fullpath << std::endl;

View File

@@ -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 ) bool DirectoryExists( const char* pzPath )
{ {
if ( pzPath == NULL) return false; if ( pzPath == NULL) return false;

View File

@@ -19,6 +19,8 @@
bool startsWith(std::string const &fullString, std::string const &prefix); bool startsWith(std::string const &fullString, std::string const &prefix);
bool hasEnding (std::string const &fullString, std::string const &ending); 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 DirectoryExists( const char* pzPath );
bool fileExists( const char* pzPath ); bool fileExists( const char* pzPath );
std::vector<std::string> getFilesInDir(const char* dirPath); std::vector<std::string> getFilesInDir(const char* dirPath);