mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-07 04:50:54 +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)
|
||||
{
|
||||
PlateDispatcher* dispatcher = (PlateDispatcher*) arg;
|
||||
|
||||
if (dispatcher->config->debugGeneral)
|
||||
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->postProcessor->analyze(plateResult.region, dispatcher->topN);
|
||||
|
||||
//plateResult.characters = ocr->postProcessor->bestChars;
|
||||
const vector<PPResult> ppResults = dispatcher->ocr->postProcessor->getResults();
|
||||
dispatcher->ocrMutex.unlock();
|
||||
|
||||
int bestPlateIndex = 0;
|
||||
|
||||
|
@@ -141,7 +141,6 @@ class PlateDispatcher
|
||||
return recognitionResults;
|
||||
}
|
||||
|
||||
|
||||
StateIdentifier* stateIdentifier;
|
||||
OCR* ocr;
|
||||
Config* config;
|
||||
@@ -150,9 +149,12 @@ class PlateDispatcher
|
||||
bool detectRegion;
|
||||
std::string defaultRegion;
|
||||
|
||||
tthread::mutex ocrMutex;
|
||||
|
||||
private:
|
||||
|
||||
tthread::mutex mMutex;
|
||||
|
||||
cv::Mat* frame;
|
||||
vector<PlateRegion> plateRegions;
|
||||
vector<AlprResult> recognitionResults;
|
||||
|
Reference in New Issue
Block a user