Fix AMD ALPR_OCR and custom model
This commit is contained in:
@@ -221,6 +221,11 @@ namespace ANSCENTER
|
||||
|
||||
bool ANSALPR_OCR::LoadEngine() {
|
||||
std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
// RAII guard: set _modelLoading=true for the lifetime of this scope.
|
||||
// RunInference / RunInferencesBatch consult this flag and silently
|
||||
// defer (instead of logging "Model is not initialized") while we're
|
||||
// loading the LP detector + OCR engine + colour classifier.
|
||||
ModelLoadingGuard mlg(_modelLoading);
|
||||
try {
|
||||
WriteEventLog("ANSALPR_OCR::LoadEngine: Step 1 - Starting engine load");
|
||||
this->_logger.LogInfo("ANSALPR_OCR::LoadEngine", "Step 1: Starting engine load", __FILE__, __LINE__);
|
||||
@@ -1479,22 +1484,28 @@ namespace ANSCENTER
|
||||
this->_logger.LogError("ANSALPR_OCR::RunInference", "Invalid license", __FILE__, __LINE__);
|
||||
return {};
|
||||
}
|
||||
if (!_isInitialized) {
|
||||
this->_logger.LogError("ANSALPR_OCR::RunInference", "Model is not initialized", __FILE__, __LINE__);
|
||||
|
||||
// LoadEngine() may be running on another thread (3+ seconds for all
|
||||
// models). Silently defer instead of spamming "Model is not
|
||||
// initialized" — the caller will retry on the next frame.
|
||||
if (_modelLoading.load(std::memory_order_acquire)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
// Source-of-truth check on the actual engine pointers. If LoadEngine
|
||||
// failed or Destroy() was called, _lpDetector / _ocrEngine are null
|
||||
// and we want a real error logged so the operator sees it.
|
||||
if (!_lpDetector || !_ocrEngine) {
|
||||
this->_logger.LogError("ANSALPR_OCR::RunInference",
|
||||
"Model not loaded (LoadEngine not called or failed)",
|
||||
__FILE__, __LINE__);
|
||||
return {};
|
||||
}
|
||||
|
||||
if (input.empty() || input.cols < 5 || input.rows < 5) {
|
||||
this->_logger.LogError("ANSALPR_OCR::RunInference", "Input image is empty or too small", __FILE__, __LINE__);
|
||||
return {};
|
||||
}
|
||||
if (!_lpDetector) {
|
||||
this->_logger.LogFatal("ANSALPR_OCR::RunInference", "_lpDetector is null", __FILE__, __LINE__);
|
||||
return {};
|
||||
}
|
||||
if (!_ocrEngine) {
|
||||
this->_logger.LogFatal("ANSALPR_OCR::RunInference", "_ocrEngine is null", __FILE__, __LINE__);
|
||||
return {};
|
||||
}
|
||||
|
||||
try {
|
||||
// Convert grayscale to BGR if necessary
|
||||
@@ -1856,19 +1867,25 @@ namespace ANSCENTER
|
||||
this->_logger.LogError("ANSALPR_OCR::RunInferencesBatch", "Invalid license", __FILE__, __LINE__);
|
||||
return {};
|
||||
}
|
||||
if (!_isInitialized) {
|
||||
this->_logger.LogError("ANSALPR_OCR::RunInferencesBatch", "Model is not initialized", __FILE__, __LINE__);
|
||||
|
||||
// LoadEngine() may be running on another thread (3+ seconds for all
|
||||
// models). Silently defer instead of spamming "Model is not
|
||||
// initialized" — the caller will retry on the next frame.
|
||||
if (_modelLoading.load(std::memory_order_acquire)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
// Source-of-truth check on the actual engine pointers. If LoadEngine
|
||||
// failed or Destroy() was called, _lpDetector / _ocrEngine are null
|
||||
// and we want a real error logged so the operator sees it.
|
||||
if (!_lpDetector || !_ocrEngine) {
|
||||
this->_logger.LogError("ANSALPR_OCR::RunInferencesBatch",
|
||||
"Model not loaded (LoadEngine not called or failed)",
|
||||
__FILE__, __LINE__);
|
||||
return {};
|
||||
}
|
||||
|
||||
if (input.empty() || input.cols < 5 || input.rows < 5) return {};
|
||||
if (!_lpDetector) {
|
||||
this->_logger.LogFatal("ANSALPR_OCR::RunInferencesBatch", "_lpDetector is null", __FILE__, __LINE__);
|
||||
return {};
|
||||
}
|
||||
if (!_ocrEngine) {
|
||||
this->_logger.LogFatal("ANSALPR_OCR::RunInferencesBatch", "_ocrEngine is null", __FILE__, __LINE__);
|
||||
return {};
|
||||
}
|
||||
if (vehicleBoxes.empty()) return {};
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user