Remove trailing whitespace

This commit is contained in:
Philippe Vaucher
2014-03-17 10:35:09 +01:00
parent b86a6743de
commit bdc922c69a
90 changed files with 3466 additions and 3523 deletions

View File

@@ -1,18 +1,18 @@
/*
* Copyright (c) 2013 New Designs Unlimited, LLC
* Opensource Automated License Plate Recognition [http://www.openalpr.com]
*
*
* This file is part of OpenAlpr.
*
*
* OpenAlpr is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License
* version 3 as published by the Free Software Foundation
*
* it under the terms of the GNU Affero General Public License
* version 3 as published by the Free Software Foundation
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@@ -23,19 +23,19 @@
PostProcess::PostProcess(Config* config)
{
this->config = config;
stringstream filename;
filename << config->getPostProcessRuntimeDir() << "/" << config->country << ".patterns";
std::ifstream infile(filename.str().c_str());
string region, pattern;
while (infile >> region >> pattern)
{
RegexRule* rule = new RegexRule(region, pattern);
//cout << "REGION: " << region << " PATTERN: " << pattern << endl;
if (rules.find(region) == rules.end())
{
vector<RegexRule*> newRule;
@@ -49,7 +49,7 @@ PostProcess::PostProcess(Config* config)
rules[region] = oldRule;
}
}
//vector<RegexRule> test = rules["base"];
//for (int i = 0; i < test.size(); i++)
// cout << "Rule: " << test[i].regex << endl;
@@ -66,7 +66,7 @@ PostProcess::~PostProcess()
{
delete iter->second[i];
}
}
}
@@ -75,28 +75,28 @@ void PostProcess::addLetter(char letter, int charposition, float score)
{
if (score < config->postProcessMinConfidence)
return;
insertLetter(letter, charposition, score);
if (score < config->postProcessConfidenceSkipLevel)
{
float adjustedScore = abs(config->postProcessConfidenceSkipLevel - score) + config->postProcessMinConfidence;
insertLetter(SKIP_CHAR, charposition, adjustedScore );
}
//if (letter == '0')
//{
// insertLetter('O', charposition, score - 0.5);
//}
}
void PostProcess::insertLetter(char letter, int charposition, float score)
{
score = score - config->postProcessMinConfidence;
int existingIndex = -1;
if (letters.size() < charposition + 1)
{
@@ -106,7 +106,7 @@ void PostProcess::insertLetter(char letter, int charposition, float score)
letters.push_back(tmp);
}
}
for (int i = 0; i < letters[charposition].size(); i++)
{
if (letters[charposition][i].letter == letter &&
@@ -116,7 +116,7 @@ void PostProcess::insertLetter(char letter, int charposition, float score)
break;
}
}
if (existingIndex == -1)
{
Letter newLetter;
@@ -131,7 +131,7 @@ void PostProcess::insertLetter(char letter, int charposition, float score)
letters[charposition][existingIndex].occurences = letters[charposition][existingIndex].occurences + 1;
letters[charposition][existingIndex].totalscore = letters[charposition][existingIndex].totalscore + score;
}
}
@@ -142,23 +142,23 @@ void PostProcess::clear()
letters[i].clear();
}
letters.resize(0);
unknownCharPositions.clear();
unknownCharPositions.resize(0);
allPossibilities.clear();
//allPossibilities.resize(0);
bestChars = "";
matchesTemplate = false;
}
void PostProcess::analyze(string templateregion, int topn)
{
timespec startTime;
getTime(&startTime);
// Get a list of missing positions
for (int i = letters.size() -1; i >= 0; i--)
{
@@ -167,38 +167,38 @@ void PostProcess::analyze(string templateregion, int topn)
unknownCharPositions.push_back(i);
}
}
if (letters.size() == 0)
return;
// Sort the letters as they are
for (int i = 0; i < letters.size(); i++)
{
if (letters[i].size() > 0)
sort(letters[i].begin(), letters[i].end(), letterCompare);
}
if (this->config->debugPostProcess)
{
// Print all letters
for (int i = 0; i < letters.size(); i++)
{
for (int j = 0; j < letters[i].size(); j++)
cout << "PostProcess Letter: " << letters[i][j].charposition << " " << letters[i][j].letter << " -- score: " << letters[i][j].totalscore << " -- occurences: " << letters[i][j].occurences << endl;
}
}
// Prune the letters based on the topN value.
// If our topN value is 3, for example, we can get rid of a lot of low scoring letters
// because it would be impossible for them to be a part of our topN results.
vector<int> maxDepth = getMaxDepth(topn);
for (int i = 0; i < letters.size(); i++)
{
for (int k = letters[i].size() - 1; k > maxDepth[i]; k--)
@@ -206,37 +206,37 @@ void PostProcess::analyze(string templateregion, int topn)
letters[i].erase(letters[i].begin() + k);
}
}
//getTopN();
vector<Letter> tmp;
findAllPermutations(tmp, 0, config->postProcessMaxSubstitutions);
timespec sortStartTime;
getTime(&sortStartTime);
int numelements = topn;
if (allPossibilities.size() < topn)
numelements = allPossibilities.size() - 1;
partial_sort( allPossibilities.begin(), allPossibilities.begin() + numelements, allPossibilities.end(), wordCompare );
if (config->debugTiming)
{
timespec sortEndTime;
getTime(&sortEndTime);
cout << " -- PostProcess Sort Time: " << diffclock(sortStartTime, sortEndTime) << "ms." << endl;
}
matchesTemplate = false;
if (templateregion != "")
{
vector<RegexRule*> regionRules = rules[templateregion];
for (int i = 0; i < allPossibilities.size(); i++)
{
for (int j = 0; j < regionRules.size(); j++)
@@ -250,16 +250,16 @@ void PostProcess::analyze(string templateregion, int topn)
break;
}
}
if (i >= topn - 1)
break;
//if (matchesTemplate || i >= TOP_N - 1)
//break;
}
}
if (matchesTemplate)
{
for (int z = 0; z < allPossibilities.size(); z++)
@@ -275,26 +275,26 @@ void PostProcess::analyze(string templateregion, int topn)
{
bestChars = allPossibilities[0].letters;
}
// Now adjust the confidence scores to a percentage value
if (allPossibilities.size() > 0)
{
float maxPercentScore = calculateMaxConfidenceScore();
float highestRelativeScore = (float) allPossibilities[0].totalscore;
for (int i = 0; i < allPossibilities.size(); i++)
{
allPossibilities[i].totalscore = maxPercentScore * (allPossibilities[i].totalscore / highestRelativeScore);
}
}
if (this->config->debugPostProcess)
{
// Print top words
for (int i = 0; i < allPossibilities.size(); i++)
{
@@ -302,22 +302,22 @@ void PostProcess::analyze(string templateregion, int topn)
if (allPossibilities[i].letters == bestChars)
cout << " <--- ";
cout << endl;
if (i >= topn - 1)
break;
}
cout << allPossibilities.size() << " total permutations" << endl;
}
if (config->debugTiming)
{
timespec endTime;
getTime(&endTime);
cout << "PostProcess Time: " << diffclock(startTime, endTime) << "ms." << endl;
}
if (this->config->debugPostProcess)
cout << "PostProcess Analysis Complete: " << bestChars << " -- MATCH: " << matchesTemplate << endl;
}
@@ -325,7 +325,7 @@ void PostProcess::analyze(string templateregion, int topn)
float PostProcess::calculateMaxConfidenceScore()
{
// Take the best score for each char position and average it.
float totalScore = 0;
int numScores = 0;
// Get a list of missing positions
@@ -337,15 +337,15 @@ float PostProcess::calculateMaxConfidenceScore()
numScores++;
}
}
if (numScores == 0)
return 0;
return totalScore / ((float) numScores);
}
// Finds the minimum number of letters to include in the recursive sorting algorithm.
// For example, if I have letters
// For example, if I have letters
// A-200 B-100 C-100
// X-99 Y-95 Z-90
// Q-55 R-80
@@ -356,23 +356,23 @@ float PostProcess::calculateMaxConfidenceScore()
// Y-95 Z-90
vector<int> PostProcess::getMaxDepth(int topn)
{
vector<int> depth;
for (int i = 0; i < letters.size(); i++)
depth.push_back(0);
int nextLeastDropCharPos = getNextLeastDrop(depth);
while (nextLeastDropCharPos != -1)
{
if (getPermutationCount(depth) >= topn)
break;
depth[nextLeastDropCharPos] = depth[nextLeastDropCharPos] + 1;
nextLeastDropCharPos = getNextLeastDrop(depth);
}
return depth;
}
@@ -383,7 +383,7 @@ int PostProcess::getPermutationCount(vector<int> depth)
{
permutationCount *= (depth[i] + 1);
}
return permutationCount;
}
@@ -391,21 +391,21 @@ int PostProcess::getNextLeastDrop(vector<int> depth)
{
int nextLeastDropCharPos = -1;
float leastNextDrop = 99999999999;
for (int i = 0; i < letters.size(); i++)
{
if (depth[i] + 1 >= letters[i].size())
continue;
float drop = letters[i][depth[i]].totalscore - letters[i][depth[i]+1].totalscore;
if (drop < leastNextDrop)
{
nextLeastDropCharPos = i;
leastNextDrop = drop;
}
}
return nextLeastDropCharPos;
}
@@ -416,14 +416,14 @@ const vector<PPResult> PostProcess::getResults()
void PostProcess::findAllPermutations(vector<Letter> prevletters, int charPos, int substitutionsLeft)
{
if (substitutionsLeft < 0)
return;
// Add my letter to the chain and recurse
for (int i = 0; i < letters[charPos].size(); i++)
{
if (charPos == letters.size() - 1)
{
// Last letter, add the word
@@ -437,27 +437,27 @@ void PostProcess::findAllPermutations(vector<Letter> prevletters, int charPos, i
possibility.letters = possibility.letters + prevletters[z].letter;
possibility.totalscore = possibility.totalscore + prevletters[z].totalscore;
}
if (letters[charPos][i].letter != SKIP_CHAR)
possibility.letters = possibility.letters + letters[charPos][i].letter;
possibility.totalscore = possibility.totalscore +letters[charPos][i].totalscore;
allPossibilities.push_back(possibility);
}
else
{
prevletters.push_back(letters[charPos][i]);
float scorePercentDiff = abs( letters[charPos][0].totalscore - letters[charPos][i].totalscore ) / letters[charPos][0].totalscore;
if (i != 0 && letters[charPos][i].letter != SKIP_CHAR && scorePercentDiff > 0.10f )
findAllPermutations(prevletters, charPos + 1, substitutionsLeft - 1);
else
findAllPermutations(prevletters, charPos + 1, substitutionsLeft);
prevletters.pop_back();
}
}
if (letters[charPos].size() == 0)
{
// No letters for this char position...
@@ -465,8 +465,8 @@ void PostProcess::findAllPermutations(vector<Letter> prevletters, int charPos, i
findAllPermutations(prevletters, charPos + 1, substitutionsLeft);
}
}
@@ -491,7 +491,7 @@ RegexRule::RegexRule(string region, string pattern)
{
this->original = pattern;
this->region = region;
numchars = 0;
for (int i = 0; i < pattern.size(); i++)
{
@@ -503,7 +503,7 @@ RegexRule::RegexRule(string region, string pattern)
i++;
}
this->regex = this->regex + ']';
}
else if (pattern.at(i) == '?')
{
@@ -518,12 +518,12 @@ RegexRule::RegexRule(string region, string pattern)
{
this->regex = this->regex + "\\d";
}
numchars++;
}
trexp.Compile(this->regex.c_str());
//cout << "AA " << this->region << ": " << original << " regex: " << regex << endl;
//for (int z = 0; z < this->skipPositions.size(); z++)
// cout << "AA Skip position: " << skipPositions[z] << endl;
@@ -534,7 +534,7 @@ bool RegexRule::match(string text)
{
if (text.length() != numchars)
return false;
return trexp.Match(text.c_str());
}
@@ -552,10 +552,10 @@ string RegexRule::filterSkips(string text)
break;
}
}
if (skip == false)
response = response + text[i];
}
return response;
}