mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-06 06:46:53 +08:00
Moved Tesseract and PostProcessor to class variables rather than pointers
This commit is contained in:
@@ -150,8 +150,8 @@ AlprFullDetails AlprImpl::recognizeFullDetails(cv::Mat img, std::vector<cv::Rect
|
|||||||
|
|
||||||
|
|
||||||
ocr->performOCR(&pipeline_data);
|
ocr->performOCR(&pipeline_data);
|
||||||
ocr->postProcessor->analyze(plateResult.region, topN);
|
ocr->postProcessor.analyze(plateResult.region, topN);
|
||||||
const vector<PPResult> ppResults = ocr->postProcessor->getResults();
|
const vector<PPResult> ppResults = ocr->postProcessor.getResults();
|
||||||
|
|
||||||
|
|
||||||
int bestPlateIndex = 0;
|
int bestPlateIndex = 0;
|
||||||
|
@@ -24,32 +24,28 @@ using namespace cv;
|
|||||||
using namespace tesseract;
|
using namespace tesseract;
|
||||||
|
|
||||||
OCR::OCR(Config* config)
|
OCR::OCR(Config* config)
|
||||||
|
: postProcessor(config)
|
||||||
{
|
{
|
||||||
const string EXPECTED_TESSERACT_VERSION = "3.03";
|
const string EXPECTED_TESSERACT_VERSION = "3.03";
|
||||||
|
|
||||||
this->config = config;
|
this->config = config;
|
||||||
|
|
||||||
this->postProcessor = new PostProcess(config);
|
|
||||||
|
|
||||||
tesseract=new TessBaseAPI();
|
if (startsWith(tesseract.Version(), EXPECTED_TESSERACT_VERSION) == false)
|
||||||
|
|
||||||
if (startsWith(tesseract->Version(), EXPECTED_TESSERACT_VERSION) == false)
|
|
||||||
{
|
{
|
||||||
std::cerr << "Warning: You are running an unsupported version of Tesseract." << endl;
|
std::cerr << "Warning: You are running an unsupported version of Tesseract." << endl;
|
||||||
std::cerr << "Expecting version " << EXPECTED_TESSERACT_VERSION << ", your version is: " << tesseract->Version() << endl;
|
std::cerr << "Expecting version " << EXPECTED_TESSERACT_VERSION << ", your version is: " << tesseract.Version() << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tesseract requires the prefix directory to be set as an env variable
|
// Tesseract requires the prefix directory to be set as an env variable
|
||||||
tesseract->Init(config->getTessdataPrefix().c_str(), config->ocrLanguage.c_str() );
|
tesseract.Init(config->getTessdataPrefix().c_str(), config->ocrLanguage.c_str() );
|
||||||
tesseract->SetVariable("save_blob_choices", "T");
|
tesseract.SetVariable("save_blob_choices", "T");
|
||||||
tesseract->SetPageSegMode(PSM_SINGLE_CHAR);
|
tesseract.SetPageSegMode(PSM_SINGLE_CHAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
OCR::~OCR()
|
OCR::~OCR()
|
||||||
{
|
{
|
||||||
tesseract->Clear();
|
tesseract.Clear();
|
||||||
delete postProcessor;
|
|
||||||
delete tesseract;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OCR::performOCR(PipelineData* pipeline_data)
|
void OCR::performOCR(PipelineData* pipeline_data)
|
||||||
@@ -57,7 +53,7 @@ void OCR::performOCR(PipelineData* pipeline_data)
|
|||||||
timespec startTime;
|
timespec startTime;
|
||||||
getTime(&startTime);
|
getTime(&startTime);
|
||||||
|
|
||||||
postProcessor->clear();
|
postProcessor.clear();
|
||||||
|
|
||||||
// Don't waste time on OCR processing if it is impossible to get sufficient characters
|
// Don't waste time on OCR processing if it is impossible to get sufficient characters
|
||||||
if (pipeline_data->charRegions.size() < config->postProcessMinCharacters)
|
if (pipeline_data->charRegions.size() < config->postProcessMinCharacters)
|
||||||
@@ -67,7 +63,7 @@ void OCR::performOCR(PipelineData* pipeline_data)
|
|||||||
{
|
{
|
||||||
// Make it black text on white background
|
// Make it black text on white background
|
||||||
bitwise_not(pipeline_data->thresholds[i], pipeline_data->thresholds[i]);
|
bitwise_not(pipeline_data->thresholds[i], pipeline_data->thresholds[i]);
|
||||||
tesseract->SetImage((uchar*) pipeline_data->thresholds[i].data,
|
tesseract.SetImage((uchar*) pipeline_data->thresholds[i].data,
|
||||||
pipeline_data->thresholds[i].size().width, pipeline_data->thresholds[i].size().height,
|
pipeline_data->thresholds[i].size().width, pipeline_data->thresholds[i].size().height,
|
||||||
pipeline_data->thresholds[i].channels(), pipeline_data->thresholds[i].step1());
|
pipeline_data->thresholds[i].channels(), pipeline_data->thresholds[i].step1());
|
||||||
|
|
||||||
@@ -75,10 +71,10 @@ void OCR::performOCR(PipelineData* pipeline_data)
|
|||||||
{
|
{
|
||||||
Rect expandedRegion = expandRect( pipeline_data->charRegions[j], 2, 2, pipeline_data->thresholds[i].cols, pipeline_data->thresholds[i].rows) ;
|
Rect expandedRegion = expandRect( pipeline_data->charRegions[j], 2, 2, pipeline_data->thresholds[i].cols, pipeline_data->thresholds[i].rows) ;
|
||||||
|
|
||||||
tesseract->SetRectangle(expandedRegion.x, expandedRegion.y, expandedRegion.width, expandedRegion.height);
|
tesseract.SetRectangle(expandedRegion.x, expandedRegion.y, expandedRegion.width, expandedRegion.height);
|
||||||
tesseract->Recognize(NULL);
|
tesseract.Recognize(NULL);
|
||||||
|
|
||||||
tesseract::ResultIterator* ri = tesseract->GetIterator();
|
tesseract::ResultIterator* ri = tesseract.GetIterator();
|
||||||
tesseract::PageIteratorLevel level = tesseract::RIL_SYMBOL;
|
tesseract::PageIteratorLevel level = tesseract::RIL_SYMBOL;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@@ -92,7 +88,7 @@ void OCR::performOCR(PipelineData* pipeline_data)
|
|||||||
|
|
||||||
if(symbol != 0 && pointsize >= config->ocrMinFontSize)
|
if(symbol != 0 && pointsize >= config->ocrMinFontSize)
|
||||||
{
|
{
|
||||||
postProcessor->addLetter(string(symbol), j, conf);
|
postProcessor.addLetter(string(symbol), j, conf);
|
||||||
|
|
||||||
if (this->config->debugOcr)
|
if (this->config->debugOcr)
|
||||||
printf("charpos%d: threshold %d: symbol %s, conf: %f font: %s (index %d) size %dpx", j, i, symbol, conf, fontName, fontindex, pointsize);
|
printf("charpos%d: threshold %d: symbol %s, conf: %f font: %s (index %d) size %dpx", j, i, symbol, conf, fontName, fontindex, pointsize);
|
||||||
@@ -103,7 +99,7 @@ void OCR::performOCR(PipelineData* pipeline_data)
|
|||||||
{
|
{
|
||||||
const char* choice = ci.GetUTF8Text();
|
const char* choice = ci.GetUTF8Text();
|
||||||
|
|
||||||
postProcessor->addLetter(string(choice), j, ci.Confidence());
|
postProcessor.addLetter(string(choice), j, ci.Confidence());
|
||||||
|
|
||||||
//letterScores.addScore(*choice, j, ci.Confidence() - MIN_CONFIDENCE);
|
//letterScores.addScore(*choice, j, ci.Confidence() - MIN_CONFIDENCE);
|
||||||
if (this->config->debugOcr)
|
if (this->config->debugOcr)
|
||||||
|
@@ -43,15 +43,12 @@ class OCR
|
|||||||
|
|
||||||
void performOCR(PipelineData* pipeline_data);
|
void performOCR(PipelineData* pipeline_data);
|
||||||
|
|
||||||
PostProcess* postProcessor;
|
PostProcess postProcessor;
|
||||||
//string recognizedText;
|
|
||||||
//float confidence;
|
|
||||||
//float overallConfidence;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Config* config;
|
Config* config;
|
||||||
|
|
||||||
tesseract::TessBaseAPI *tesseract;
|
tesseract::TessBaseAPI tesseract;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user