Fix mutex lock issues (OCR and FR)
This commit is contained in:
@@ -12,6 +12,7 @@ bool PaddleOCRV5RTEngine::Initialize(const std::string& detModelPath,
|
||||
int gpuId,
|
||||
const std::string& engineCacheDir) {
|
||||
std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
ModelLoadingGuard mlg(_modelLoading);
|
||||
|
||||
gpuId_ = gpuId;
|
||||
if (!engineCacheDir.empty()) {
|
||||
@@ -57,10 +58,15 @@ bool PaddleOCRV5RTEngine::Initialize(const std::string& detModelPath,
|
||||
}
|
||||
|
||||
std::vector<OCRPredictResult> PaddleOCRV5RTEngine::ocr(const cv::Mat& image) {
|
||||
std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
std::vector<OCRPredictResult> results;
|
||||
if (_modelLoading.load()) return {};
|
||||
|
||||
if (!detector_ || !recognizer_ || image.empty()) return results;
|
||||
std::vector<OCRPredictResult> results;
|
||||
{
|
||||
auto lk = TryLockWithTimeout("PaddleOCRV5RTEngine::ocr");
|
||||
if (!lk.owns_lock()) return results;
|
||||
if (!detector_ || !recognizer_ || image.empty()) return results;
|
||||
}
|
||||
// _mutex released — heavy pipeline runs lock-free
|
||||
|
||||
try {
|
||||
// 1. Detection: find text boxes
|
||||
@@ -148,8 +154,12 @@ std::vector<OCRPredictResult> PaddleOCRV5RTEngine::ocr(const cv::Mat& image) {
|
||||
}
|
||||
|
||||
TextLine PaddleOCRV5RTEngine::recognizeOnly(const cv::Mat& croppedImage) {
|
||||
std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
if (!recognizer_ || croppedImage.empty()) return { "", 0.0f };
|
||||
if (_modelLoading.load()) return { "", 0.0f };
|
||||
{
|
||||
auto lk = TryLockWithTimeout("PaddleOCRV5RTEngine::recognizeOnly");
|
||||
if (!lk.owns_lock()) return { "", 0.0f };
|
||||
if (!recognizer_ || croppedImage.empty()) return { "", 0.0f };
|
||||
}
|
||||
return recognizer_->Recognize(croppedImage);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user