diff --git a/src/openalpr/postprocess/postprocess.cpp b/src/openalpr/postprocess/postprocess.cpp index 05a9c7a..b9ee9d2 100644 --- a/src/openalpr/postprocess/postprocess.cpp +++ b/src/openalpr/postprocess/postprocess.cpp @@ -297,16 +297,19 @@ namespace alpr vector v(letters.size()); permutations.push(make_pair(totalscore, v)); + int consecutiveNonMatches = 0; while (permutations.size() > 0) { // get the top permutation and analyze pair > topPermutation = permutations.top(); - analyzePermutation(topPermutation.second, templateregion, topn); + if (analyzePermutation(topPermutation.second, templateregion, topn) == true) + consecutiveNonMatches = 0; + else + consecutiveNonMatches += 1; permutations.pop(); - if (allPossibilities.size() >= topn) { + if (allPossibilities.size() >= topn || consecutiveNonMatches >= 10) break; - } // add child permutations to queue for (int i=0; i letterIndices, string templateregion, int topn) + bool PostProcess::analyzePermutation(vector letterIndices, string templateregion, int topn) { PPResult possibility; possibility.letters = ""; @@ -356,7 +359,7 @@ namespace alpr // ignore plates that don't fit the length requirements if (plate_char_length < config->postProcessMinCharacters || plate_char_length > config->postProcessMaxCharacters) - return; + return false; // Apply templates if (templateregion != "") @@ -376,10 +379,11 @@ namespace alpr // ignore duplicate words if (allPossibilitiesLetters.end() != allPossibilitiesLetters.find(possibility.letters)) - return; + return false; allPossibilities.push_back(possibility); allPossibilitiesLetters.insert(possibility.letters); + return true; } bool wordCompare( const PPResult &left, const PPResult &right ) diff --git a/src/openalpr/postprocess/postprocess.h b/src/openalpr/postprocess/postprocess.h index 04ee040..203c10a 100644 --- a/src/openalpr/postprocess/postprocess.h +++ b/src/openalpr/postprocess/postprocess.h @@ -79,7 +79,7 @@ namespace alpr Config* config; //void getTopN(); void findAllPermutations(std::string templateregion, int topn); - void analyzePermutation(std::vector letterIndices, std::string templateregion, int topn); + bool analyzePermutation(std::vector letterIndices, std::string templateregion, int topn); void insertLetter(std::string letter, int charPosition, float score);