Fix ALPR pipeline. Ready for production
This commit is contained in:
@@ -39,6 +39,18 @@ namespace ANSCENTER
|
||||
[[nodiscard]] int levenshteinDistance(const std::string& s1, const std::string& s2);
|
||||
[[nodiscard]] float computeIoU(const cv::Rect& a, const cv::Rect& b);
|
||||
[[nodiscard]] std::string majorityVote(const std::deque<std::string>& history);
|
||||
|
||||
// --- TrackId-based plate tracking (hybrid: trackId primary, Levenshtein fallback) ---
|
||||
struct TrackedPlateById {
|
||||
int trackId = 0;
|
||||
std::deque<std::string> textHistory;
|
||||
std::string lockedText;
|
||||
int lockCount = 0;
|
||||
int framesSinceLastSeen = 0;
|
||||
};
|
||||
// cameraId → (trackId → tracked plate)
|
||||
std::unordered_map<std::string, std::unordered_map<int, TrackedPlateById>> trackedPlatesById;
|
||||
|
||||
public:
|
||||
void Init(int framesToStore = MAX_ALPR_FRAME);
|
||||
ALPRChecker(int framesToStore = MAX_ALPR_FRAME) : maxFrames(framesToStore) {}
|
||||
@@ -46,6 +58,8 @@ namespace ANSCENTER
|
||||
[[nodiscard]] std::string checkPlate(const std::string& cameraId, const std::string& detectedPlate);
|
||||
// Enhanced API with bounding box for spatial plate tracking
|
||||
[[nodiscard]] std::string checkPlate(const std::string& cameraId, const std::string& detectedPlate, const cv::Rect& plateBox);
|
||||
// Hybrid API: trackId as primary identity, Levenshtein fallback for lost tracks
|
||||
[[nodiscard]] std::string checkPlateByTrackId(const std::string& cameraId, const std::string& detectedPlate, int trackId);
|
||||
};
|
||||
|
||||
class ANSLPR_API ANSALPR {
|
||||
@@ -72,6 +86,12 @@ namespace ANSCENTER
|
||||
cv::Rect _detectedArea;// Area where license plate are detected
|
||||
Country _country;
|
||||
std::recursive_mutex _mutex;
|
||||
|
||||
// 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 };
|
||||
|
||||
public:
|
||||
[[nodiscard]] virtual bool Initialize(const std::string& licenseKey, const std::string& modelZipFilePath, const std::string& modelZipPassword, double detectorThreshold, double ocrThreshold, double colourTheshold=0);
|
||||
[[nodiscard]] virtual bool LoadEngine();
|
||||
@@ -92,6 +112,13 @@ namespace ANSCENTER
|
||||
/// (LP detection, OCR, color classification, validation, serialization).
|
||||
/// Also propagates the flag to sub-detectors (_lpDetector, _ocrDetector, etc.).
|
||||
virtual void ActivateDebugger(bool debugFlag) { _debugFlag = debugFlag; }
|
||||
|
||||
/// 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; }
|
||||
|
||||
[[nodiscard]] virtual bool Destroy() = 0;
|
||||
[[nodiscard]] static std::vector<cv::Rect> GetBoundingBoxes(const std::string& strBBoxes);
|
||||
[[nodiscard]] static std::string PolygonToString(const std::vector<cv::Point2f>& polygon);
|
||||
@@ -137,11 +164,14 @@ extern "C" ANSLPR_API int ANSALPR_RunInferenceComplete_LV(ANSCENTER::ANSALPR
|
||||
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);
|
||||
extern "C" ANSLPR_API int ANSALPR_RunInferencesComplete_LV(ANSCENTER::ANSALPR** Handle, cv::Mat** cvImage, const char* cameraId, int maxImageSize,const char* strBboxes, LStrHandle detectionResult);
|
||||
|
||||
// Get/Set format
|
||||
// Get/Set format
|
||||
extern "C" ANSLPR_API int ANSALPR_SetFormat(ANSCENTER::ANSALPR** Handle, const char* format);
|
||||
extern "C" ANSLPR_API int ANSALPR_SetFormats(ANSCENTER::ANSALPR** Handle, const char* formats);// comma separated formats
|
||||
extern "C" ANSLPR_API int ANSALPR_GetFormats(ANSCENTER::ANSALPR** Handle, LStrHandle formats);// comma separated formats
|
||||
|
||||
// ALPRChecker: 1 = enabled (full-frame auto-detected), 0 = disabled (raw OCR)
|
||||
extern "C" ANSLPR_API int ANSALPR_SetALPRCheckerEnabled(ANSCENTER::ANSALPR** Handle, int enable);
|
||||
|
||||
// Unicode conversion utilities for LabVIEW wrapper classes
|
||||
extern "C" ANSLPR_API int ANSLPR_ConvertUTF8ToUTF16LE(const char* utf8Str, LStrHandle result, int includeBOM = 1);
|
||||
extern "C" ANSLPR_API int ANSLPR_ConvertUTF16LEToUTF8(const unsigned char* utf16leBytes, int byteLen, LStrHandle result);
|
||||
|
||||
Reference in New Issue
Block a user