mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-16 12:10:42 +08:00
Added generic OCR wrapper for Tesseract
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
#include "endtoendtest.h"
|
||||
|
||||
#include "detection/detectorfactory.h"
|
||||
#include "ocr/ocrfactory.h"
|
||||
#include "support/filesystem.h"
|
||||
|
||||
using namespace std;
|
||||
@@ -169,7 +170,7 @@ int main( int argc, const char** argv )
|
||||
|
||||
PreWarp prewarp(&config);
|
||||
Detector* plateDetector = createDetector(&config, &prewarp);
|
||||
OCR ocr(&config);
|
||||
OCR* ocr = createOcr(&config);
|
||||
|
||||
vector<double> endToEndTimes;
|
||||
vector<double> regionDetectionTimes;
|
||||
@@ -230,14 +231,14 @@ int main( int argc, const char** argv )
|
||||
lpAnalysisPositiveTimes.push_back(analysisTime);
|
||||
|
||||
getTimeMonotonic(&startTime);
|
||||
ocr.performOCR(&pipeline_data);
|
||||
ocr->performOCR(&pipeline_data);
|
||||
getTimeMonotonic(&endTime);
|
||||
double ocrTime = diffclock(startTime, endTime);
|
||||
cout << "\tRegion " << z << ": OCR time: " << ocrTime << "ms." << endl;
|
||||
ocrTimes.push_back(ocrTime);
|
||||
|
||||
getTimeMonotonic(&startTime);
|
||||
ocr.postProcessor.analyze("", 25);
|
||||
ocr->postProcessor.analyze("", 25);
|
||||
getTimeMonotonic(&endTime);
|
||||
double postProcessTime = diffclock(startTime, endTime);
|
||||
cout << "\tRegion " << z << ": PostProcess time: " << postProcessTime << "ms." << endl;
|
||||
|
@@ -28,7 +28,8 @@
|
||||
#include "licenseplatecandidate.h"
|
||||
#include "utility.h"
|
||||
#include "support/filesystem.h"
|
||||
#include "ocr.h"
|
||||
#include "ocr/ocrfactory.h"
|
||||
#include "ocr/ocr.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
@@ -120,7 +121,7 @@ int main( int argc, const char** argv )
|
||||
config.debugGeneral = false;
|
||||
config.debugCharAnalysis = false;
|
||||
config.debugCharSegmenter = false;
|
||||
OCR ocr(&config);
|
||||
OCR* ocr = createOcr(&config);
|
||||
|
||||
if (DirectoryExists(inDir.c_str()))
|
||||
{
|
||||
@@ -162,9 +163,9 @@ int main( int argc, const char** argv )
|
||||
|
||||
//ocr.cleanCharRegions(charSegmenter.thresholds, charSegmenter.characters);
|
||||
|
||||
ocr.performOCR(&pipeline_data);
|
||||
ocr.postProcessor.analyze(statecodestr, 25);
|
||||
cout << "OCR results: " << ocr.postProcessor.bestChars << endl;
|
||||
ocr->performOCR(&pipeline_data);
|
||||
ocr->postProcessor.analyze(statecodestr, 25);
|
||||
cout << "OCR results: " << ocr->postProcessor.bestChars << endl;
|
||||
|
||||
vector<bool> selectedBoxes(pipeline_data.thresholds.size());
|
||||
for (int z = 0; z < pipeline_data.thresholds.size(); z++)
|
||||
|
@@ -15,7 +15,9 @@ set(lpr_source_files
|
||||
detection/detectormask.cpp
|
||||
licenseplatecandidate.cpp
|
||||
utility.cpp
|
||||
ocr.cpp
|
||||
ocr/tesseract_ocr.cpp
|
||||
ocr/ocr.cpp
|
||||
ocr/ocrfactory.cpp
|
||||
postprocess/postprocess.cpp
|
||||
postprocess/regexrule.cpp
|
||||
binarize_wolf.cpp
|
||||
|
@@ -736,7 +736,7 @@ namespace alpr
|
||||
// Country training data has not already been loaded. Load it.
|
||||
AlprRecognizers recognizer;
|
||||
recognizer.plateDetector = createDetector(config, prewarp);
|
||||
recognizer.ocr = new OCR(config);
|
||||
recognizer.ocr = createOcr(config);
|
||||
|
||||
#ifndef SKIP_STATE_DETECTION
|
||||
recognizer.stateDetector = new StateDetector(this->config->country, this->config->config_file_path, this->config->runtimeBaseDir);
|
||||
|
@@ -37,7 +37,8 @@
|
||||
#include "licenseplatecandidate.h"
|
||||
#include "../statedetection/state_detector.h"
|
||||
#include "segmentation/charactersegmenter.h"
|
||||
#include "ocr.h"
|
||||
#include "ocr/ocr.h"
|
||||
#include "ocr/ocrfactory.h"
|
||||
|
||||
#include "constants.h"
|
||||
|
||||
|
33
src/openalpr/ocr/ocr.cpp
Normal file
33
src/openalpr/ocr/ocr.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2015 OpenALPR Technology, Inc.
|
||||
* Open source 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
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include "ocr.h"
|
||||
|
||||
namespace alpr
|
||||
{
|
||||
|
||||
OCR::OCR(Config* config) : postProcessor(config) {
|
||||
this->config = config;
|
||||
}
|
||||
|
||||
|
||||
OCR::~OCR() {
|
||||
}
|
||||
|
||||
}
|
44
src/openalpr/ocr/ocr.h
Normal file
44
src/openalpr/ocr/ocr.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2015 OpenALPR Technology, Inc.
|
||||
* Open source 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
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef OPENALPR_OCR_H
|
||||
#define OPENALPR_OCR_H
|
||||
|
||||
#include "postprocess/postprocess.h"
|
||||
#include "pipeline_data.h"
|
||||
|
||||
namespace alpr
|
||||
{
|
||||
class OCR {
|
||||
public:
|
||||
OCR(Config* config);
|
||||
virtual ~OCR();
|
||||
|
||||
virtual void performOCR(PipelineData* pipeline_data)=0;
|
||||
|
||||
PostProcess postProcessor;
|
||||
|
||||
protected:
|
||||
Config* config;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* OPENALPR_OCR_H */
|
||||
|
12
src/openalpr/ocr/ocrfactory.cpp
Normal file
12
src/openalpr/ocr/ocrfactory.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "ocrfactory.h"
|
||||
#include "tesseract_ocr.h"
|
||||
|
||||
namespace alpr
|
||||
{
|
||||
OCR* createOcr(Config* config)
|
||||
{
|
||||
return new TesseractOcr(config);
|
||||
}
|
||||
|
||||
}
|
||||
|
33
src/openalpr/ocr/ocrfactory.h
Normal file
33
src/openalpr/ocr/ocrfactory.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2015 OpenALPR Technology, Inc.
|
||||
* Open source 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
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef OPENALPR_OCRFACTORY_H
|
||||
#define OPENALPR_OCRFACTORY_H
|
||||
|
||||
#include "config.h"
|
||||
#include "ocr.h"
|
||||
|
||||
namespace alpr
|
||||
{
|
||||
|
||||
OCR* createOcr(Config* config);
|
||||
|
||||
}
|
||||
#endif /* OPENALPR_DETECTORFACTORY_H */
|
||||
|
@@ -17,7 +17,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "ocr.h"
|
||||
#include "tesseract_ocr.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
@@ -26,12 +26,11 @@ using namespace tesseract;
|
||||
namespace alpr
|
||||
{
|
||||
|
||||
OCR::OCR(Config* config)
|
||||
: postProcessor(config)
|
||||
TesseractOcr::TesseractOcr(Config* config)
|
||||
: OCR(config)
|
||||
{
|
||||
const string MINIMUM_TESSERACT_VERSION = "3.03";
|
||||
|
||||
this->config = config;
|
||||
|
||||
if (cmpVersion(tesseract.Version(), MINIMUM_TESSERACT_VERSION.c_str()) < 0)
|
||||
{
|
||||
@@ -46,12 +45,12 @@ namespace alpr
|
||||
tesseract.SetPageSegMode(PSM_SINGLE_CHAR);
|
||||
}
|
||||
|
||||
OCR::~OCR()
|
||||
TesseractOcr::~TesseractOcr()
|
||||
{
|
||||
tesseract.End();
|
||||
}
|
||||
|
||||
void OCR::performOCR(PipelineData* pipeline_data)
|
||||
void TesseractOcr::performOCR(PipelineData* pipeline_data)
|
||||
{
|
||||
const int SPACE_CHAR_CODE = 32;
|
||||
|
@@ -17,14 +17,13 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef OPENALPR_OCR_H
|
||||
#define OPENALPR_OCR_H
|
||||
#ifndef OPENALPR_TESSERACTOCR_H
|
||||
#define OPENALPR_TESSERACTOCR_H
|
||||
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "utility.h"
|
||||
#include "postprocess/postprocess.h"
|
||||
#include "config.h"
|
||||
#include "pipeline_data.h"
|
||||
|
||||
@@ -33,24 +32,23 @@
|
||||
#include "support/filesystem.h"
|
||||
#include "support/version.h"
|
||||
|
||||
#include "ocr.h"
|
||||
#include "tesseract/baseapi.h"
|
||||
|
||||
namespace alpr
|
||||
{
|
||||
|
||||
class OCR
|
||||
class TesseractOcr : public OCR
|
||||
{
|
||||
|
||||
public:
|
||||
OCR(Config* config);
|
||||
virtual ~OCR();
|
||||
TesseractOcr(Config* config);
|
||||
virtual ~TesseractOcr();
|
||||
|
||||
void performOCR(PipelineData* pipeline_data);
|
||||
|
||||
PostProcess postProcessor;
|
||||
|
||||
private:
|
||||
Config* config;
|
||||
|
||||
tesseract::TessBaseAPI tesseract;
|
||||
|
||||
@@ -58,4 +56,4 @@ namespace alpr
|
||||
|
||||
}
|
||||
|
||||
#endif // OPENALPR_OCR_H
|
||||
#endif // OPENALPR_TESSERACTOCR_H
|
Reference in New Issue
Block a user