Added limit in post processing to stop after 10 consecutive non-valid permutations

This commit is contained in:
psaintjust
2015-06-28 17:33:24 -04:00
parent a55cce71d4
commit 9330e59a28
2 changed files with 11 additions and 7 deletions

View File

@@ -297,16 +297,19 @@ namespace alpr
vector<int> v(letters.size()); vector<int> v(letters.size());
permutations.push(make_pair(totalscore, v)); permutations.push(make_pair(totalscore, v));
int consecutiveNonMatches = 0;
while (permutations.size() > 0) while (permutations.size() > 0)
{ {
// get the top permutation and analyze // get the top permutation and analyze
pair<float, vector<int> > topPermutation = permutations.top(); pair<float, vector<int> > topPermutation = permutations.top();
analyzePermutation(topPermutation.second, templateregion, topn); if (analyzePermutation(topPermutation.second, templateregion, topn) == true)
consecutiveNonMatches = 0;
else
consecutiveNonMatches += 1;
permutations.pop(); permutations.pop();
if (allPossibilities.size() >= topn) { if (allPossibilities.size() >= topn || consecutiveNonMatches >= 10)
break; break;
}
// add child permutations to queue // add child permutations to queue
for (int i=0; i<letters.size(); i++) for (int i=0; i<letters.size(); i++)
@@ -329,7 +332,7 @@ namespace alpr
} }
} }
void PostProcess::analyzePermutation(vector<int> letterIndices, string templateregion, int topn) bool PostProcess::analyzePermutation(vector<int> letterIndices, string templateregion, int topn)
{ {
PPResult possibility; PPResult possibility;
possibility.letters = ""; possibility.letters = "";
@@ -356,7 +359,7 @@ namespace alpr
// ignore plates that don't fit the length requirements // ignore plates that don't fit the length requirements
if (plate_char_length < config->postProcessMinCharacters || if (plate_char_length < config->postProcessMinCharacters ||
plate_char_length > config->postProcessMaxCharacters) plate_char_length > config->postProcessMaxCharacters)
return; return false;
// Apply templates // Apply templates
if (templateregion != "") if (templateregion != "")
@@ -376,10 +379,11 @@ namespace alpr
// ignore duplicate words // ignore duplicate words
if (allPossibilitiesLetters.end() != allPossibilitiesLetters.find(possibility.letters)) if (allPossibilitiesLetters.end() != allPossibilitiesLetters.find(possibility.letters))
return; return false;
allPossibilities.push_back(possibility); allPossibilities.push_back(possibility);
allPossibilitiesLetters.insert(possibility.letters); allPossibilitiesLetters.insert(possibility.letters);
return true;
} }
bool wordCompare( const PPResult &left, const PPResult &right ) bool wordCompare( const PPResult &left, const PPResult &right )

View File

@@ -79,7 +79,7 @@ namespace alpr
Config* config; Config* config;
//void getTopN(); //void getTopN();
void findAllPermutations(std::string templateregion, int topn); void findAllPermutations(std::string templateregion, int topn);
void analyzePermutation(std::vector<int> letterIndices, std::string templateregion, int topn); bool analyzePermutation(std::vector<int> letterIndices, std::string templateregion, int topn);
void insertLetter(std::string letter, int charPosition, float score); void insertLetter(std::string letter, int charPosition, float score);