Added mutex around OCR. Tesseract does not appear to be threadsafe

This commit is contained in:
Matt Hill
2014-05-04 15:18:17 -05:00
parent d6c79299fb
commit 7e2646aab0
2 changed files with 8 additions and 5 deletions

View File

@@ -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;

View File

@@ -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;