mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-07 23:20:04 +08:00
Added mutex around OCR. Tesseract does not appear to be threadsafe
This commit is contained in:
@@ -153,6 +153,7 @@ std::vector<AlprResult> AlprImpl::recognize(cv::Mat img)
|
|||||||
void plateAnalysisThread(void* arg)
|
void plateAnalysisThread(void* arg)
|
||||||
{
|
{
|
||||||
PlateDispatcher* dispatcher = (PlateDispatcher*) arg;
|
PlateDispatcher* dispatcher = (PlateDispatcher*) arg;
|
||||||
|
|
||||||
if (dispatcher->config->debugGeneral)
|
if (dispatcher->config->debugGeneral)
|
||||||
cout << "Thread: " << tthread::this_thread::get_id() << " Initialized" << endl;
|
cout << "Thread: " << tthread::this_thread::get_id() << " Initialized" << endl;
|
||||||
|
|
||||||
@@ -208,12 +209,12 @@ void plateAnalysisThread(void* arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Tesseract OCR does not appear to be threadsafe
|
||||||
|
dispatcher->ocrMutex.lock();
|
||||||
dispatcher->ocr->performOCR(lp.charSegmenter->getThresholds(), lp.charSegmenter->characters);
|
dispatcher->ocr->performOCR(lp.charSegmenter->getThresholds(), lp.charSegmenter->characters);
|
||||||
|
|
||||||
dispatcher->ocr->postProcessor->analyze(plateResult.region, dispatcher->topN);
|
dispatcher->ocr->postProcessor->analyze(plateResult.region, dispatcher->topN);
|
||||||
|
|
||||||
//plateResult.characters = ocr->postProcessor->bestChars;
|
|
||||||
const vector<PPResult> ppResults = dispatcher->ocr->postProcessor->getResults();
|
const vector<PPResult> ppResults = dispatcher->ocr->postProcessor->getResults();
|
||||||
|
dispatcher->ocrMutex.unlock();
|
||||||
|
|
||||||
int bestPlateIndex = 0;
|
int bestPlateIndex = 0;
|
||||||
|
|
||||||
|
@@ -141,7 +141,6 @@ class PlateDispatcher
|
|||||||
return recognitionResults;
|
return recognitionResults;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
StateIdentifier* stateIdentifier;
|
StateIdentifier* stateIdentifier;
|
||||||
OCR* ocr;
|
OCR* ocr;
|
||||||
Config* config;
|
Config* config;
|
||||||
@@ -150,9 +149,12 @@ class PlateDispatcher
|
|||||||
bool detectRegion;
|
bool detectRegion;
|
||||||
std::string defaultRegion;
|
std::string defaultRegion;
|
||||||
|
|
||||||
|
tthread::mutex ocrMutex;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
tthread::mutex mMutex;
|
tthread::mutex mMutex;
|
||||||
|
|
||||||
cv::Mat* frame;
|
cv::Mat* frame;
|
||||||
vector<PlateRegion> plateRegions;
|
vector<PlateRegion> plateRegions;
|
||||||
vector<AlprResult> recognitionResults;
|
vector<AlprResult> recognitionResults;
|
||||||
|
Reference in New Issue
Block a user