mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-05 23:36:54 +08:00
Parameterized min_confidence and skip_level
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
|
||||
#include "tesseract_ocr.h"
|
||||
#include "config.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
@@ -31,6 +32,7 @@ namespace alpr
|
||||
{
|
||||
const string MINIMUM_TESSERACT_VERSION = "3.03";
|
||||
|
||||
this->postProcessor.setConfidenceThreshold(config->postProcessMinConfidence, config->postProcessConfidenceSkipLevel);
|
||||
|
||||
if (cmpVersion(tesseract.Version(), MINIMUM_TESSERACT_VERSION.c_str()) < 0)
|
||||
{
|
||||
|
@@ -28,6 +28,9 @@ namespace alpr
|
||||
{
|
||||
this->config = config;
|
||||
|
||||
this->min_confidence = 0;
|
||||
this->skip_level = 0;
|
||||
|
||||
stringstream filename;
|
||||
filename << config->getPostProcessRuntimeDir() << "/" << config->country << ".patterns";
|
||||
|
||||
@@ -53,9 +56,6 @@ namespace alpr
|
||||
}
|
||||
}
|
||||
|
||||
//vector<RegexRule> test = rules["base"];
|
||||
//for (int i = 0; i < test.size(); i++)
|
||||
// cout << "Rule: " << test[i].regex << endl;
|
||||
}
|
||||
|
||||
PostProcess::~PostProcess()
|
||||
@@ -72,16 +72,22 @@ namespace alpr
|
||||
}
|
||||
}
|
||||
|
||||
void PostProcess::setConfidenceThreshold(float min_confidence, float skip_level) {
|
||||
this->min_confidence = min_confidence;
|
||||
this->skip_level = skip_level;
|
||||
}
|
||||
|
||||
|
||||
void PostProcess::addLetter(string letter, int line_index, int charposition, float score)
|
||||
{
|
||||
if (score < config->postProcessMinConfidence)
|
||||
if (score < min_confidence)
|
||||
return;
|
||||
|
||||
insertLetter(letter, line_index, charposition, score);
|
||||
|
||||
if (score < config->postProcessConfidenceSkipLevel)
|
||||
if (score < skip_level)
|
||||
{
|
||||
float adjustedScore = abs(config->postProcessConfidenceSkipLevel - score) + config->postProcessMinConfidence;
|
||||
float adjustedScore = abs(skip_level - score) + min_confidence;
|
||||
insertLetter(SKIP_CHAR, line_index, charposition, adjustedScore );
|
||||
}
|
||||
|
||||
@@ -93,7 +99,7 @@ namespace alpr
|
||||
|
||||
void PostProcess::insertLetter(string letter, int line_index, int charposition, float score)
|
||||
{
|
||||
score = score - config->postProcessMinConfidence;
|
||||
score = score - min_confidence;
|
||||
|
||||
int existingIndex = -1;
|
||||
if (letters.size() < charposition + 1)
|
||||
@@ -260,7 +266,7 @@ namespace alpr
|
||||
{
|
||||
if (letters[i].size() > 0)
|
||||
{
|
||||
totalScore += (letters[i][0].totalscore / letters[i][0].occurrences) + config->postProcessMinConfidence;
|
||||
totalScore += (letters[i][0].totalscore / letters[i][0].occurrences) + min_confidence;
|
||||
numScores++;
|
||||
}
|
||||
}
|
||||
|
@@ -77,6 +77,8 @@ namespace alpr
|
||||
|
||||
std::vector<std::string> getPatterns();
|
||||
|
||||
void setConfidenceThreshold(float min_confidence, float skip_level);
|
||||
|
||||
private:
|
||||
Config* config;
|
||||
|
||||
@@ -94,6 +96,9 @@ namespace alpr
|
||||
|
||||
std::vector<PPResult> allPossibilities;
|
||||
std::set<std::string> allPossibilitiesLetters;
|
||||
|
||||
float min_confidence;
|
||||
float skip_level;
|
||||
};
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user