disable ALPR checker by default

This commit is contained in:
2026-05-05 04:37:23 +10:00
parent 91d81cbd88
commit d03c2c1138
8 changed files with 1192 additions and 12 deletions
+26 -3
View File
@@ -145,7 +145,16 @@ namespace ANSCENTER
// ALPRChecker toggle (Layer 2 + Layer 3):
// true = enabled for full-frame, auto-disabled for pipeline/crop
// false = force disabled everywhere (raw OCR pass-through)
bool _enableALPRChecker{ true };
// Default OFF — callers must opt in with SetALPRCheckerEnabled(true)
// to get tracker voting / skip-when-locked / spatial dedup. Keeps
// the out-of-the-box pipeline stateless so first-frame results match
// per-frame results exactly, and avoids surprises for callers that
// drive the engine with pre-cropped pipeline inputs.
// Atomic so the inference threads can read it without a lock while
// config threads (LabVIEW/UI/REST) flip it at runtime. Relaxed
// ordering is sufficient: we only need the read to be tear-free, and
// "next frame picks up the new value" is the intended contract.
std::atomic<bool> _enableALPRChecker{ false };
public:
[[nodiscard]] virtual bool Initialize(const std::string& licenseKey, const std::string& modelZipFilePath, const std::string& modelZipPassword, double detectorThreshold, double ocrThreshold, double colourTheshold=0);
@@ -193,8 +202,20 @@ namespace ANSCENTER
/// Enable/disable ALPRChecker (Layer 2 text stabilization + Layer 3 dedup):
/// true = enabled for full-frame, auto-disabled for pipeline/crop
/// false = force disabled everywhere (raw OCR pass-through)
void SetALPRCheckerEnabled(bool enable) { _enableALPRChecker = enable; }
bool IsALPRCheckerEnabled() const { return _enableALPRChecker; }
void SetALPRCheckerEnabled(bool enable) {
const bool prev = _enableALPRChecker.exchange(enable, std::memory_order_relaxed);
ANS_DBG("ALPR_Checker",
"SetALPRCheckerEnabled this=%p prev=%d new=%d (%s)",
(void*)this, prev ? 1 : 0, enable ? 1 : 0,
enable ? "ON" : "OFF");
}
bool IsALPRCheckerEnabled() const {
const bool value = _enableALPRChecker.load(std::memory_order_relaxed);
ANS_DBG("ALPR_Checker",
"IsALPRCheckerEnabled this=%p value=%d (%s)",
(void*)this, value ? 1 : 0, value ? "ON" : "OFF");
return value;
}
virtual void SetCountry(Country country) { _country = country; }
Country GetCountry() const { return _country; }
@@ -262,6 +283,8 @@ extern "C" ANSLPR_API int ANSALPR_GetFormats(ANSCENTER::ANSALPR** Handle, LS
// ALPRChecker: 1 = enabled (full-frame auto-detected), 0 = disabled (raw OCR)
extern "C" ANSLPR_API int ANSALPR_SetALPRCheckerEnabled(ANSCENTER::ANSALPR** Handle, int enable);
// Returns the current ALPRChecker flag: 1 = enabled, 0 = disabled, -1 = invalid handle.
extern "C" ANSLPR_API int ANSALPR_GetALPRCheckerEnabled(ANSCENTER::ANSALPR** Handle);
// Country: 0=VIETNAM, 1=CHINA, 2=AUSTRALIA, 3=USA, 4=INDONESIA, 5=JAPAN
extern "C" ANSLPR_API int ANSALPR_SetCountry(ANSCENTER::ANSALPR** Handle, int country);
+4 -2
View File
@@ -1231,8 +1231,10 @@ namespace ANSCENTER
// ALPRChecker voting + ensureUniquePlateText dedup.
bool ANSALPR_OCR::shouldUseALPRChecker(const cv::Size& imageSize,
const std::string& cameraId) {
// Force disabled via SetALPRCheckerEnabled(false) → never use.
if (!_enableALPRChecker) return false;
// Force disabled via SetALPRCheckerEnabled(false) → never use. Relaxed
// atomic load: tear-free read is all we need, "next frame sees the new
// value" is the intended contract.
if (!_enableALPRChecker.load(std::memory_order_relaxed)) return false;
// Small images are always pipeline crops — skip auto-detection.
if (imageSize.width < ImageSizeTracker::MIN_FULLFRAME_WIDTH) return false;
+3 -2
View File
@@ -1041,8 +1041,9 @@ namespace ANSCENTER {
// voting and ensureUniquePlateText dedup in all Inference/RunInference paths.
if (!_enableTrackerVoting) return false;
// Force disabled → never use
if (!_enableALPRChecker) return false;
// Force disabled → never use. Relaxed load is fine: tear-free read of a
// single bool is all we need; "next frame sees the new value" is the contract.
if (!_enableALPRChecker.load(std::memory_order_relaxed)) return false;
// Small images are always pipeline crops — skip auto-detection
if (imageSize.width < ImageSizeTracker::MIN_FULLFRAME_WIDTH) return false;
+29 -1
View File
@@ -965,7 +965,11 @@ extern "C" ANSLPR_API int ANSALPR_SetFormats(ANSCENTER::ANSALPR** Handle, co
extern "C" ANSLPR_API int ANSALPR_SetALPRCheckerEnabled(ANSCENTER::ANSALPR** Handle, int enable) {
ANS_DBG("ANSLPR","ANSALPR_SetALPRCheckerEnabled: HandlePtr=%p, *Handle=%p, enable=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), enable);
if (!Handle || !*Handle) return -1;
if (!Handle || !*Handle) {
ANS_DBG("ALPR_Checker",
"ANSALPR_SetALPRCheckerEnabled: invalid handle, returning -1");
return -1;
}
try {
(*Handle)->SetALPRCheckerEnabled(enable != 0);
ANS_DBG("ALPR_Checker", "SetALPRCheckerEnabled=%d (%s)",
@@ -973,10 +977,34 @@ extern "C" ANSLPR_API int ANSALPR_SetALPRCheckerEnabled(ANSCENTER::ANSALPR**
return 1;
}
catch (...) {
ANS_DBG("ALPR_Checker",
"ANSALPR_SetALPRCheckerEnabled: exception caught, returning 0");
return 0;
}
}
// Returns the current ALPRChecker flag: 1 = enabled, 0 = disabled, -1 = invalid handle.
extern "C" ANSLPR_API int ANSALPR_GetALPRCheckerEnabled(ANSCENTER::ANSALPR** Handle) {
ANS_DBG("ANSLPR","ANSALPR_GetALPRCheckerEnabled: HandlePtr=%p, *Handle=%p",
(void*)Handle, (void*)(Handle ? *Handle : nullptr));
if (!Handle || !*Handle) {
ANS_DBG("ALPR_Checker",
"ANSALPR_GetALPRCheckerEnabled: invalid handle, returning -1");
return -1;
}
try {
const bool enabled = (*Handle)->IsALPRCheckerEnabled();
ANS_DBG("ALPR_Checker", "GetALPRCheckerEnabled=%d (%s)",
enabled ? 1 : 0, enabled ? "ON" : "OFF");
return enabled ? 1 : 0;
}
catch (...) {
ANS_DBG("ALPR_Checker",
"ANSALPR_GetALPRCheckerEnabled: exception caught, returning -1");
return -1;
}
}
extern "C" ANSLPR_API int ANSALPR_SetCountry(ANSCENTER::ANSALPR** Handle, int country) {
ANS_DBG("ANSLPR","ANSALPR_SetCountry: HandlePtr=%p, *Handle=%p, country=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), country);