- Remove ALPR_OD Tracker and voting system.

- Disable debugview
This commit is contained in:
2026-04-19 23:15:50 +10:00
parent 51fe507dfd
commit 3418090042
13 changed files with 1266 additions and 129 deletions

View File

@@ -1032,6 +1032,11 @@ namespace ANSCENTER {
}
bool ANSALPR_OD::shouldUseALPRChecker(const cv::Size& imageSize, const std::string& cameraId) {
// Master switch for tracker + voting post-processing. Off by default;
// flip with SetTrackerVotingEnabled(true) to re-enable alprChecker
// voting and ensureUniquePlateText dedup in all Inference/RunInference paths.
if (!_enableTrackerVoting) return false;
// Force disabled → never use
if (!_enableALPRChecker) return false;

View File

@@ -164,6 +164,12 @@ namespace ANSCENTER
// Tri-state: -1 = auto-detect (default), 0 = explicitly disabled, 1 = explicitly enabled
// _enableALPRChecker is inherited from ANSALPR base class
// Master switch for tracker + voting post-processing inside
// RunInference / RunInferenceSingleFrame. When false, these methods
// return raw per-frame OCR output (no alprChecker.checkPlateByTrackId
// voting, no spatial ensureUniquePlateText dedup). Default: disabled.
bool _enableTrackerVoting{ false };
struct ImageSizeTracker {
cv::Size lastSize{0, 0};
int consistentCount = 0;
@@ -252,6 +258,9 @@ namespace ANSCENTER
}
// SetALPRCheckerEnabled() and IsALPRCheckerEnabled() inherited from ANSALPR base class
void SetTrackerVotingEnabled(bool enable) { _enableTrackerVoting = enable; }
[[nodiscard]] bool IsTrackerVotingEnabled() const { return _enableTrackerVoting; }
};
}
#endif

View File

@@ -12,6 +12,8 @@
#include <condition_variable>
#include <cstdint>
// DebugView: filter on "[ANSLPR]" — gated by ANSCORE_DEBUGVIEW in ANSLicense.h.
// Write a message to Windows Event Log (Application log, source "ANSLogger").
// Works even when spdlog is not initialized — useful for crash diagnostics.
static void WriteWindowsEventLog(const char* message, WORD eventType = EVENTLOG_ERROR_TYPE) {
@@ -48,6 +50,8 @@ static std::condition_variable& ALPRHandleRegistryCV() {
static void RegisterALPRHandle(ANSCENTER::ANSALPR* h) {
std::lock_guard<std::mutex> lk(ALPRHandleRegistryMutex());
ALPRHandleRegistry()[h] = { 1, false };
ANS_DBG("ANSLPR","Register: handle=%p (uint=%llu) registrySize=%zu",
(void*)h, (unsigned long long)(uintptr_t)h, ALPRHandleRegistry().size());
}
// Acquire a handle for use (increment refcount). Returns the handle
@@ -55,9 +59,23 @@ static void RegisterALPRHandle(ANSCENTER::ANSALPR* h) {
static ANSCENTER::ANSALPR* AcquireALPRHandle(ANSCENTER::ANSALPR* h) {
std::lock_guard<std::mutex> lk(ALPRHandleRegistryMutex());
auto it = ALPRHandleRegistry().find(h);
if (it == ALPRHandleRegistry().end()) return nullptr;
if (it->second.destructionStarted) return nullptr;
if (it == ALPRHandleRegistry().end()) {
ANS_DBG("ANSLPR","Acquire FAIL: handle=%p (uint=%llu) NOT in registry. registrySize=%zu",
(void*)h, (unsigned long long)(uintptr_t)h, ALPRHandleRegistry().size());
size_t i = 0;
for (auto& kv : ALPRHandleRegistry()) {
ANS_DBG("ANSLPR"," registry[%zu] = %p (uint=%llu) refcount=%d destructionStarted=%d",
i++, (void*)kv.first, (unsigned long long)(uintptr_t)kv.first,
kv.second.refcount, kv.second.destructionStarted ? 1 : 0);
}
return nullptr;
}
if (it->second.destructionStarted) {
ANS_DBG("ANSLPR","Acquire FAIL: handle=%p is being destroyed (destructionStarted=true)", (void*)h);
return nullptr;
}
it->second.refcount++;
ANS_DBG("ANSLPR","Acquire OK: handle=%p refcount=%d", (void*)h, it->second.refcount);
return h;
}
@@ -79,11 +97,16 @@ static bool ReleaseALPRHandleRef(ANSCENTER::ANSALPR* h) {
static bool UnregisterALPRHandle(ANSCENTER::ANSALPR* h) {
std::unique_lock<std::mutex> lk(ALPRHandleRegistryMutex());
auto it = ALPRHandleRegistry().find(h);
if (it == ALPRHandleRegistry().end()) return false;
if (it->second.destructionStarted) {
// Another thread already owns the delete — back off.
if (it == ALPRHandleRegistry().end()) {
ANS_DBG("ANSLPR","Unregister: handle=%p NOT in registry (already gone)", (void*)h);
return false;
}
if (it->second.destructionStarted) {
// Another thread already owns the delete — back off.
ANS_DBG("ANSLPR","Unregister: handle=%p already being destroyed by another thread, returning false", (void*)h);
return false;
}
ANS_DBG("ANSLPR","Unregister: handle=%p starting (refcount before=%d)", (void*)h, it->second.refcount);
it->second.destructionStarted = true;
it->second.refcount--; // Remove creation ref
bool ok = ALPRHandleRegistryCV().wait_for(lk, std::chrono::seconds(30), [&]() {
@@ -91,6 +114,7 @@ static bool UnregisterALPRHandle(ANSCENTER::ANSALPR* h) {
return it2 == ALPRHandleRegistry().end() || it2->second.refcount <= 0;
});
if (!ok) {
ANS_DBG("ANSLPR","WARNING: Unregister timed out waiting for in-flight operations on handle=%p", (void*)h);
OutputDebugStringA("WARNING: UnregisterALPRHandle timed out waiting for in-flight inference\n");
}
ALPRHandleRegistry().erase(h);
@@ -142,6 +166,10 @@ BOOL APIENTRY DllMain( HMODULE hModule,
static int CreateANSALPRHandle_Impl(ANSCENTER::ANSALPR** Handle, const char* licenseKey, const char* modelZipFilePath, const char* modelZipPassword,
int engineType, double detectorThreshold, double ocrThreshold, double colourThreshold) {
ANS_DBG("ANSLPR","Create called: HandlePtr=%p, *Handle(in)=%p, engineType=%d, detTh=%.3f, ocrTh=%.3f, colTh=%.3f, modelZip=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), engineType, detectorThreshold, ocrThreshold, colourThreshold,
modelZipFilePath ? modelZipFilePath : "(null)");
if (Handle == nullptr) { ANS_DBG("ANSLPR","Create FAIL: Handle is null"); return 0; }
try {
// Ensure all shared DLLs (OpenCV, OpenVINO, TRT, ORT) are pre-loaded
ANSCENTER::ANSLibsLoader::Initialize();
@@ -166,31 +194,41 @@ static int CreateANSALPRHandle_Impl(ANSCENTER::ANSALPR** Handle, const char* lic
(*Handle) = new ANSCENTER::ANSALPR_OCR();// ONNX OCR (PaddleOCR v5)
}
else {
ANS_DBG("ANSLPR","Create FAIL: unknown engineType=%d", engineType);
return 0;
}
if (*Handle == nullptr) return 0;
if (*Handle == nullptr) { ANS_DBG("ANSLPR","Create FAIL: new returned null for engineType=%d", engineType); return 0; }
else {
ANS_DBG("ANSLPR","Create: allocated handle=%p (uint=%llu) engineType=%d, calling Initialize...",
(void*)*Handle, (unsigned long long)(uintptr_t)*Handle, engineType);
RegisterALPRHandle(*Handle);
int result = (*Handle)->Initialize(licenseKey, modelZipFilePath, modelZipPassword, detectorThreshold, ocrThreshold,colourThreshold);
ANS_DBG("ANSLPR","Create: Initialize returned %d for handle=%p (uint=%llu)",
result, (void*)*Handle, (unsigned long long)(uintptr_t)*Handle);
return result;
}
}
catch (std::exception& e) {
ANS_DBG("ANSLPR","Create EXCEPTION (std::exception): %s", e.what());
return 0;
}
catch (...) {
ANS_DBG("ANSLPR","Create EXCEPTION (unknown)");
return 0;
}
}
extern "C" ANSLPR_API int CreateANSALPRHandle(ANSCENTER::ANSALPR * *Handle, const char* licenseKey, const char* modelZipFilePath, const char* modelZipPassword,
int engineType, double detectorThreshold, double ocrThreshold, double colourThreshold) {
ANS_DBG("ANSLPR","CreateANSALPRHandle: HandlePtr=%p, *Handle=%p, engineType=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), engineType);
__try {
return CreateANSALPRHandle_Impl(Handle, licenseKey, modelZipFilePath, modelZipPassword, engineType, detectorThreshold, ocrThreshold, colourThreshold);
}
__except (EXCEPTION_EXECUTE_HANDLER) {
char buf[256];
snprintf(buf, sizeof(buf), "ANSLPR CreateANSALPRHandle: SEH exception 0x%08X caught during initialization", GetExceptionCode());
ANS_DBG("ANSLPR","CreateANSALPRHandle: SEH exception caught");
WriteWindowsEventLog(buf);
if (Handle) *Handle = nullptr;
return 0;
@@ -213,17 +251,22 @@ static int LoadANSALPREngineHandle_Impl(ANSCENTER::ANSALPR** Handle) {
}
extern "C" ANSLPR_API int LoadANSALPREngineHandle(ANSCENTER::ANSALPR** Handle) {
ANS_DBG("ANSLPR","LoadANSALPREngineHandle: HandlePtr=%p, *Handle=%p",
(void*)Handle, (void*)(Handle ? *Handle : nullptr));
__try {
return LoadANSALPREngineHandle_Impl(Handle);
}
__except (EXCEPTION_EXECUTE_HANDLER) {
char buf[256];
snprintf(buf, sizeof(buf), "ANSLPR LoadANSALPREngineHandle: SEH exception 0x%08X caught during engine load", GetExceptionCode());
ANS_DBG("ANSLPR","LoadANSALPREngineHandle: SEH exception caught");
WriteWindowsEventLog(buf);
return 0;
}
}
extern "C" ANSLPR_API std::string ANSALPR_RunInference(ANSCENTER::ANSALPR * *Handle, unsigned char* jpeg_string, unsigned int bufferLength) {
ANS_DBG("ANSLPR","ANSALPR_RunInference: HandlePtr=%p, *Handle=%p, bufferLength=%u",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength);
if (!Handle || !*Handle) return "";
ALPRHandleGuard guard(AcquireALPRHandle(*Handle));
if (!guard) return "";
@@ -240,6 +283,8 @@ extern "C" ANSLPR_API std::string ANSALPR_RunInference(ANSCENTER::ANSALPR * *Ha
}
extern "C" ANSLPR_API std::string ANSALPR_RunInferenceWithCamID(ANSCENTER::ANSALPR** Handle, unsigned char* jpeg_string, unsigned int bufferLength, const char* cameraId) {
ANS_DBG("ANSLPR","ANSALPR_RunInferenceWithCamID: HandlePtr=%p, *Handle=%p, bufferLength=%u, cameraId=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength, cameraId ? cameraId : "(null)");
if (!Handle || !*Handle) return "";
ALPRHandleGuard guard(AcquireALPRHandle(*Handle));
if (!guard) return "";
@@ -256,6 +301,8 @@ extern "C" ANSLPR_API std::string ANSALPR_RunInferenceWithCamID(ANSCENTER::ANSA
}
extern "C" ANSLPR_API std::string ANSALPR_RunInferenceInCroppedImages(ANSCENTER::ANSALPR * *Handle, unsigned char* jpeg_string, unsigned int bufferLength, const char* strBboxes) {
ANS_DBG("ANSLPR","ANSALPR_RunInferenceInCroppedImages: HandlePtr=%p, *Handle=%p, bufferLength=%u, strBboxes=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength, strBboxes ? strBboxes : "(null)");
if (!Handle || !*Handle) return "";
ALPRHandleGuard guard(AcquireALPRHandle(*Handle));
if (!guard) return "";
@@ -274,6 +321,8 @@ extern "C" ANSLPR_API std::string ANSALPR_RunInferenceInCroppedImages(ANSCENTER
}
extern "C" ANSLPR_API std::string ANSALPR_RunInferenceInCroppedImagesWithCamID(ANSCENTER::ANSALPR** Handle, unsigned char* jpeg_string, unsigned int bufferLength, const char* strBboxes, const char* cameraId) {
ANS_DBG("ANSLPR","ANSALPR_RunInferenceInCroppedImagesWithCamID: HandlePtr=%p, *Handle=%p, bufferLength=%u, strBboxes=%s, cameraId=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength, strBboxes ? strBboxes : "(null)", cameraId ? cameraId : "(null)");
if (!Handle || !*Handle) return "";
ALPRHandleGuard guard(AcquireALPRHandle(*Handle));
if (!guard) return "";
@@ -292,6 +341,8 @@ extern "C" ANSLPR_API std::string ANSALPR_RunInferenceInCroppedImagesWithCamID(
}
extern "C" ANSLPR_API std::string ANSALPR_RunInferenceBinary(ANSCENTER::ANSALPR * *Handle, unsigned char* jpeg_bytes, unsigned int width, unsigned int height) {
ANS_DBG("ANSLPR","ANSALPR_RunInferenceBinary: HandlePtr=%p, *Handle=%p, width=%u, height=%u",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), width, height);
if (!Handle || !*Handle || !jpeg_bytes || width == 0 || height == 0) return "";
ALPRHandleGuard guard(AcquireALPRHandle(*Handle));
if (!guard) return "";
@@ -309,6 +360,8 @@ extern "C" ANSLPR_API std::string ANSALPR_RunInferenceBinary(ANSCENTER::ANSALPR
extern "C" ANSLPR_API std::string ANSALPR_RunInferenceBinaryInCroppedImages(ANSCENTER::ANSALPR * *Handle, unsigned char* jpeg_bytes, unsigned int width, unsigned int height, const char* strBboxes) {
ANS_DBG("ANSLPR","ANSALPR_RunInferenceBinaryInCroppedImages: HandlePtr=%p, *Handle=%p, width=%u, height=%u, strBboxes=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), width, height, strBboxes ? strBboxes : "(null)");
if (!Handle || !*Handle) return "";
ALPRHandleGuard guard(AcquireALPRHandle(*Handle));
if (!guard) return "";
@@ -328,32 +381,47 @@ extern "C" ANSLPR_API std::string ANSALPR_RunInferenceBinaryInCroppedImages(ANS
static int ReleaseANSALPRHandle_Impl(ANSCENTER::ANSALPR** Handle) {
try {
if (!Handle || !*Handle) return 1;
if (!UnregisterALPRHandle(*Handle)) {
if (!Handle || !*Handle) {
ANS_DBG("ANSLPR","Release: HandlePtr or *Handle is null, no-op");
return 1;
}
ANSCENTER::ANSALPR* h = *Handle;
ANS_DBG("ANSLPR","Release called: handle=%p (uint=%llu)", (void*)h, (unsigned long long)(uintptr_t)h);
if (!UnregisterALPRHandle(h)) {
ANS_DBG("ANSLPR","Release: Unregister returned false (already gone or being destroyed by another thread), handle=%p", (void*)h);
*Handle = nullptr;
return 1; // Not in registry — already freed
}
(*Handle)->Destroy();
delete *Handle;
*Handle = nullptr;
ANS_DBG("ANSLPR","Release OK: handle=%p deleted, registry now has %zu entries",
(void*)h, ALPRHandleRegistry().size());
return 1;
}
catch (...) {
ANS_DBG("ANSLPR","Release EXCEPTION (unknown)");
if (Handle) *Handle = nullptr;
return 0;
}
}
extern "C" ANSLPR_API int ReleaseANSALPRHandle(ANSCENTER::ANSALPR** Handle) {
ANS_DBG("ANSLPR","ReleaseANSALPRHandle: HandlePtr=%p, *Handle=%p",
(void*)Handle, (void*)(Handle ? *Handle : nullptr));
__try {
return ReleaseANSALPRHandle_Impl(Handle);
}
__except (EXCEPTION_EXECUTE_HANDLER) {
ANS_DBG("ANSLPR","ReleaseANSALPRHandle: SEH exception caught");
if (Handle) *Handle = nullptr;
return 0;
}
}
//// For LabVIEW API
extern "C" ANSLPR_API int ANSALPR_RunInference_LV(ANSCENTER::ANSALPR * *Handle, unsigned char* jpeg_string, unsigned int bufferLength, LStrHandle detectionResult) {
ANS_DBG("ANSLPR","ANSALPR_RunInference_LV: HandlePtr=%p, *Handle=%p, bufferLength=%u",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength);
try {
std::string st = ANSALPR_RunInference(Handle, jpeg_string, bufferLength);
if (st.empty()) return 0;
@@ -375,8 +443,10 @@ extern "C" ANSLPR_API int ANSALPR_RunInference_LV(ANSCENTER::ANSALPR * *Handl
return 0;
}
}
extern "C" ANSLPR_API int ANSALPR_RunInferenceWithCamID_LV(ANSCENTER::ANSALPR** Handle, unsigned char* jpeg_string, unsigned int bufferLength, const char* cameraId, LStrHandle detectionResult)
extern "C" ANSLPR_API int ANSALPR_RunInferenceWithCamID_LV(ANSCENTER::ANSALPR** Handle, unsigned char* jpeg_string, unsigned int bufferLength, const char* cameraId, LStrHandle detectionResult)
{
ANS_DBG("ANSLPR","ANSALPR_RunInferenceWithCamID_LV: HandlePtr=%p, *Handle=%p, bufferLength=%u, cameraId=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength, cameraId ? cameraId : "(null)");
try {
std::string st = ANSALPR_RunInferenceWithCamID(Handle, jpeg_string, bufferLength, cameraId);
if (st.empty()) return 0;
@@ -399,6 +469,8 @@ extern "C" ANSLPR_API int ANSALPR_RunInferenceWithCamID_LV(ANSCENTER::ANSALPR
}
}
extern "C" ANSLPR_API int ANSALPR_RunInferenceBinary_LV(ANSCENTER::ANSALPR * *Handle, unsigned char* jpeg_bytes, unsigned int width, unsigned int height, LStrHandle detectionResult) {
ANS_DBG("ANSLPR","ANSALPR_RunInferenceBinary_LV: HandlePtr=%p, *Handle=%p, width=%u, height=%u",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), width, height);
try {
std::string st = ANSALPR_RunInferenceBinary(Handle, jpeg_bytes, width, height);
if (st.empty()) return 0;
@@ -423,6 +495,8 @@ extern "C" ANSLPR_API int ANSALPR_RunInferenceBinary_LV(ANSCENTER::ANSALPR * *H
extern "C" ANSLPR_API int ANSALPR_RunInferenceInCroppedImages_LV(ANSCENTER::ANSALPR * *Handle, unsigned char* jpeg_string, unsigned int bufferLength, const char* strBboxes, LStrHandle detectionResult) {
ANS_DBG("ANSLPR","ANSALPR_RunInferenceInCroppedImages_LV: HandlePtr=%p, *Handle=%p, bufferLength=%u, strBboxes=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength, strBboxes ? strBboxes : "(null)");
try {
std::string st = ANSALPR_RunInferenceInCroppedImages(Handle, jpeg_string, bufferLength, strBboxes);
if (st.empty()) return 0;
@@ -446,6 +520,8 @@ extern "C" ANSLPR_API int ANSALPR_RunInferenceInCroppedImages_LV(ANSCENTER::A
}
extern "C" ANSLPR_API int ANSALPR_RunInferenceInCroppedImagesWithCamID_LV(ANSCENTER::ANSALPR** Handle, unsigned char* jpeg_string, unsigned int bufferLength, const char* strBboxes, const char* cameraId, LStrHandle detectionResult) {
ANS_DBG("ANSLPR","ANSALPR_RunInferenceInCroppedImagesWithCamID_LV: HandlePtr=%p, *Handle=%p, bufferLength=%u, strBboxes=%s, cameraId=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength, strBboxes ? strBboxes : "(null)", cameraId ? cameraId : "(null)");
try {
std::string st = ANSALPR_RunInferenceInCroppedImagesWithCamID(Handle, jpeg_string, bufferLength, strBboxes, cameraId);
if (st.empty()) return 0;
@@ -476,6 +552,9 @@ extern "C" ANSLPR_API int ANSALPR_RunInferenceComplete_LV(
LStrHandle detectionResult,
LStrHandle imageStr)
{
ANS_DBG("ANSLPR","ANSALPR_RunInferenceComplete_LV: HandlePtr=%p, *Handle=%p, cvImage=%p, cameraId=%s, getJpeg=%d, jpegImageSize=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), (void*)(cvImage ? *cvImage : nullptr),
cameraId ? cameraId : "(null)", getJpegString, jpegImageSize);
if (!Handle || !*Handle) return -1;
if (!cvImage || !(*cvImage) || (*cvImage)->empty()) return -2;
@@ -580,6 +659,9 @@ extern "C" ANSLPR_API int ANSALPR_RunInferenceComplete_LV(
extern "C" ANSLPR_API int ANSALPR_RunInferenceComplete_CPP(ANSCENTER::ANSALPR** Handle, cv::Mat** cvImage, const char* cameraId, int getJpegString, int jpegImageSize, std::string& detectionResult, std::string& imageStr) {
ANS_DBG("ANSLPR","ANSALPR_RunInferenceComplete_CPP: HandlePtr=%p, *Handle=%p, cvImage=%p, cameraId=%s, getJpeg=%d, jpegImageSize=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), (void*)(cvImage ? *cvImage : nullptr),
cameraId ? cameraId : "(null)", getJpegString, jpegImageSize);
if (!Handle || !*Handle) return -1;
if (!cvImage || !(*cvImage) || (*cvImage)->empty()) return -2;
@@ -661,6 +743,9 @@ extern "C" ANSLPR_API int ANSALPR_RunInferencesComplete_LV(
const char* strBboxes,
LStrHandle detectionResult)
{
ANS_DBG("ANSLPR","ANSALPR_RunInferencesComplete_LV: HandlePtr=%p, *Handle=%p, cvImage=%p, cameraId=%s, maxImageSize=%d, strBboxes=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), (void*)(cvImage ? *cvImage : nullptr),
cameraId ? cameraId : "(null)", maxImageSize, strBboxes ? strBboxes : "(null)");
if (!Handle || !*Handle) return -1;
if (!cvImage || !(*cvImage) || (*cvImage)->empty()) return -2;
@@ -756,6 +841,9 @@ extern "C" ANSLPR_API int ANSALPR_RunInferencesBatch_LV(
const char* strBboxes,
LStrHandle detectionResult)
{
ANS_DBG("ANSLPR","ANSALPR_RunInferencesBatch_LV: HandlePtr=%p, *Handle=%p, cvImage=%p, cameraId=%s, maxImageSize=%d, strBboxes=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), (void*)(cvImage ? *cvImage : nullptr),
cameraId ? cameraId : "(null)", maxImageSize, strBboxes ? strBboxes : "(null)");
if (!Handle || !*Handle) return -1;
if (!cvImage || !(*cvImage) || (*cvImage)->empty()) return -2;
@@ -832,6 +920,8 @@ extern "C" ANSLPR_API int ANSALPR_RunInferencesBatch_LV(
extern "C" ANSLPR_API int ANSALPR_SetFormat(ANSCENTER::ANSALPR** Handle, const char* format) {
ANS_DBG("ANSLPR","ANSALPR_SetFormat: HandlePtr=%p, *Handle=%p, format=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), format ? format : "(null)");
if (!Handle || !*Handle) return -1;
if (!format) return -1;
try {
@@ -848,6 +938,8 @@ extern "C" ANSLPR_API int ANSALPR_SetFormat(ANSCENTER::ANSALPR** Handle, con
}
extern "C" ANSLPR_API int ANSALPR_SetFormats(ANSCENTER::ANSALPR** Handle, const char* formats){// semi separated formats
ANS_DBG("ANSLPR","ANSALPR_SetFormats: HandlePtr=%p, *Handle=%p, formats=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), formats ? formats : "(null)");
if (!Handle || !*Handle) return -1;
if (!formats) return -1;
try {
@@ -871,6 +963,8 @@ extern "C" ANSLPR_API int ANSALPR_SetFormats(ANSCENTER::ANSALPR** Handle, co
// ALPRChecker: 1 = enabled (full-frame auto-detected), 0 = disabled (raw OCR)
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;
try {
(*Handle)->SetALPRCheckerEnabled(enable != 0);
@@ -884,6 +978,8 @@ extern "C" ANSLPR_API int ANSALPR_SetALPRCheckerEnabled(ANSCENTER::ANSALPR**
}
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);
if (!Handle || !*Handle) return -1;
try {
(*Handle)->SetCountry(static_cast<ANSCENTER::Country>(country));
@@ -896,6 +992,8 @@ extern "C" ANSLPR_API int ANSALPR_SetCountry(ANSCENTER::ANSALPR** Handle, in
extern "C" ANSLPR_API int ANSALPR_GetFormats(ANSCENTER::ANSALPR** Handle, LStrHandle Lstrformats)// semi separated formats
{
ANS_DBG("ANSLPR","ANSALPR_GetFormats: HandlePtr=%p, *Handle=%p",
(void*)Handle, (void*)(Handle ? *Handle : nullptr));
if (!Handle || !*Handle) return -1;
if (!Lstrformats) return -1;
try {
@@ -925,6 +1023,8 @@ extern "C" ANSLPR_API int ANSALPR_GetFormats(ANSCENTER::ANSALPR** Handle, LS
// Unicode conversion utilities for LabVIEW wrapper classes
extern "C" ANSLPR_API int ANSLPR_ConvertUTF8ToUTF16LE(const char* utf8Str, LStrHandle result, int includeBOM) {
ANS_DBG("ANSLPR","ANSLPR_ConvertUTF8ToUTF16LE: utf8Str=%p, result=%p, includeBOM=%d",
(void*)utf8Str, (void*)result, includeBOM);
try {
if (!utf8Str || !result) return -1;
int len = (int)strlen(utf8Str);
@@ -980,6 +1080,8 @@ extern "C" ANSLPR_API int ANSLPR_ConvertUTF8ToUTF16LE(const char* utf8Str, LStrH
}
extern "C" ANSLPR_API int ANSLPR_ConvertUTF16LEToUTF8(const unsigned char* utf16leBytes, int byteLen, LStrHandle result) {
ANS_DBG("ANSLPR","ANSLPR_ConvertUTF16LEToUTF8: utf16leBytes=%p, byteLen=%d, result=%p",
(void*)utf16leBytes, byteLen, (void*)result);
try {
if (!utf16leBytes || byteLen <= 0 || !result) return -1;
bool isUtf16le = (byteLen >= 2 && byteLen % 2 == 0);
@@ -1027,6 +1129,8 @@ extern "C" ANSLPR_API int ANSLPR_ConvertUTF16LEToUTF8(const unsigned char* utf16
extern "C" ANSLPR_API int ANSALPR_RunInference_LV_V2(uint64_t handleVal, unsigned char* jpeg_string, unsigned int bufferLength, LStrHandle detectionResult) {
ALPR_V2_HANDLE_SETUP(handleVal);
ANS_DBG("ANSLPR","ANSALPR_RunInference_LV_V2: handleVal=%llu handle=%p, bufferLength=%u",
(unsigned long long)handleVal, (void*)_v2Direct, bufferLength);
try {
std::string st = ANSALPR_RunInference(Handle, jpeg_string, bufferLength);
if (st.empty()) return 0;
@@ -1051,6 +1155,8 @@ extern "C" ANSLPR_API int ANSALPR_RunInference_LV_V2(uint64_t handleVal, unsigne
extern "C" ANSLPR_API int ANSALPR_RunInferenceWithCamID_LV_V2(uint64_t handleVal, unsigned char* jpeg_string, unsigned int bufferLength, const char* cameraId, LStrHandle detectionResult) {
ALPR_V2_HANDLE_SETUP(handleVal);
ANS_DBG("ANSLPR","ANSALPR_RunInferenceWithCamID_LV_V2: handleVal=%llu handle=%p, bufferLength=%u, cameraId=%s",
(unsigned long long)handleVal, (void*)_v2Direct, bufferLength, cameraId ? cameraId : "(null)");
try {
std::string st = ANSALPR_RunInferenceWithCamID(Handle, jpeg_string, bufferLength, cameraId);
if (st.empty()) return 0;
@@ -1075,6 +1181,8 @@ extern "C" ANSLPR_API int ANSALPR_RunInferenceWithCamID_LV_V2(uint64_t handleVal
extern "C" ANSLPR_API int ANSALPR_RunInferenceBinary_LV_V2(uint64_t handleVal, unsigned char* jpeg_bytes, unsigned int width, unsigned int height, LStrHandle detectionResult) {
ALPR_V2_HANDLE_SETUP(handleVal);
ANS_DBG("ANSLPR","ANSALPR_RunInferenceBinary_LV_V2: handleVal=%llu handle=%p, width=%u, height=%u",
(unsigned long long)handleVal, (void*)_v2Direct, width, height);
try {
std::string st = ANSALPR_RunInferenceBinary(Handle, jpeg_bytes, width, height);
if (st.empty()) return 0;
@@ -1099,6 +1207,8 @@ extern "C" ANSLPR_API int ANSALPR_RunInferenceBinary_LV_V2(uint64_t handleVal, u
extern "C" ANSLPR_API int ANSALPR_RunInferenceInCroppedImages_LV_V2(uint64_t handleVal, unsigned char* jpeg_string, unsigned int bufferLength, const char* strBboxes, LStrHandle detectionResult) {
ALPR_V2_HANDLE_SETUP(handleVal);
ANS_DBG("ANSLPR","ANSALPR_RunInferenceInCroppedImages_LV_V2: handleVal=%llu handle=%p, bufferLength=%u, strBboxes=%s",
(unsigned long long)handleVal, (void*)_v2Direct, bufferLength, strBboxes ? strBboxes : "(null)");
try {
std::string st = ANSALPR_RunInferenceInCroppedImages(Handle, jpeg_string, bufferLength, strBboxes);
if (st.empty()) return 0;
@@ -1123,6 +1233,8 @@ extern "C" ANSLPR_API int ANSALPR_RunInferenceInCroppedImages_LV_V2(uint64_t han
extern "C" ANSLPR_API int ANSALPR_RunInferenceInCroppedImagesWithCamID_LV_V2(uint64_t handleVal, unsigned char* jpeg_string, unsigned int bufferLength, const char* strBboxes, const char* cameraId, LStrHandle detectionResult) {
ALPR_V2_HANDLE_SETUP(handleVal);
ANS_DBG("ANSLPR","ANSALPR_RunInferenceInCroppedImagesWithCamID_LV_V2: handleVal=%llu handle=%p, bufferLength=%u, strBboxes=%s, cameraId=%s",
(unsigned long long)handleVal, (void*)_v2Direct, bufferLength, strBboxes ? strBboxes : "(null)", cameraId ? cameraId : "(null)");
try {
std::string st = ANSALPR_RunInferenceInCroppedImagesWithCamID(Handle, jpeg_string, bufferLength, strBboxes, cameraId);
if (st.empty()) return 0;
@@ -1155,6 +1267,9 @@ extern "C" ANSLPR_API int ANSALPR_RunInferenceComplete_LV_V2(
LStrHandle imageStr)
{
ANSCENTER::ANSALPR* _v2Direct = reinterpret_cast<ANSCENTER::ANSALPR*>(handleVal);
ANS_DBG("ANSLPR","ANSALPR_RunInferenceComplete_LV_V2: handleVal=%llu handle=%p, cvImage=%p, cameraId=%s, getJpeg=%d, jpegImageSize=%d",
(unsigned long long)handleVal, (void*)_v2Direct, (void*)(cvImage ? *cvImage : nullptr),
cameraId ? cameraId : "(null)", getJpegString, jpegImageSize);
if (_v2Direct == nullptr) return -1;
if (!cvImage || !(*cvImage) || (*cvImage)->empty()) return -2;
@@ -1268,6 +1383,9 @@ extern "C" ANSLPR_API int ANSALPR_RunInferencesBatch_LV_V2(
LStrHandle detectionResult)
{
ANSCENTER::ANSALPR* _v2Direct = reinterpret_cast<ANSCENTER::ANSALPR*>(handleVal);
ANS_DBG("ANSLPR","ANSALPR_RunInferencesBatch_LV_V2: handleVal=%llu handle=%p, cvImage=%p, cameraId=%s, maxImageSize=%d, strBboxes=%s",
(unsigned long long)handleVal, (void*)_v2Direct, (void*)(cvImage ? *cvImage : nullptr),
cameraId ? cameraId : "(null)", maxImageSize, strBboxes ? strBboxes : "(null)");
if (_v2Direct == nullptr) return -1;
if (!cvImage || !(*cvImage) || (*cvImage)->empty()) return -2;
@@ -1343,6 +1461,9 @@ extern "C" ANSLPR_API int ANSALPR_RunInferencesComplete_LV_V2(
LStrHandle detectionResult)
{
ANSCENTER::ANSALPR* _v2Direct = reinterpret_cast<ANSCENTER::ANSALPR*>(handleVal);
ANS_DBG("ANSLPR","ANSALPR_RunInferencesComplete_LV_V2: handleVal=%llu handle=%p, cvImage=%p, cameraId=%s, maxImageSize=%d, strBboxes=%s",
(unsigned long long)handleVal, (void*)_v2Direct, (void*)(cvImage ? *cvImage : nullptr),
cameraId ? cameraId : "(null)", maxImageSize, strBboxes ? strBboxes : "(null)");
if (_v2Direct == nullptr) return -1;
if (!cvImage || !(*cvImage) || (*cvImage)->empty()) return -2;