Unify country and ocr mode on both ANSOCR and ANSALPR

This commit is contained in:
2026-03-30 15:21:32 +11:00
parent 08fb2e9adf
commit dd2009d87a
8 changed files with 55 additions and 53 deletions

View File

@@ -5,7 +5,9 @@
"Bash(xargs grep:*)", "Bash(xargs grep:*)",
"Bash(grep -n \"~Engine\\\\|TRTEngineCache::release\\\\|EnginePoolManager::release\\\\|destructor\" /c/Projects/CLionProjects/ANSCORE/engines/TensorRTAPI/include/engine/*.inl /c/Projects/CLionProjects/ANSCORE/modules/ANSODEngine/*.h)", "Bash(grep -n \"~Engine\\\\|TRTEngineCache::release\\\\|EnginePoolManager::release\\\\|destructor\" /c/Projects/CLionProjects/ANSCORE/engines/TensorRTAPI/include/engine/*.inl /c/Projects/CLionProjects/ANSCORE/modules/ANSODEngine/*.h)",
"Bash(grep -l \"EnginePoolManager\" /c/Projects/CLionProjects/ANSCORE/modules/ANSODEngine/*.cpp)", "Bash(grep -l \"EnginePoolManager\" /c/Projects/CLionProjects/ANSCORE/modules/ANSODEngine/*.cpp)",
"Bash(grep -n \"g_processExiting\" /c/Projects/CLionProjects/ANSCORE/engines/TensorRTAPI/include/engine/*.h /c/Projects/CLionProjects/ANSCORE/modules/ANSODEngine/engine.h)" "Bash(grep -n \"g_processExiting\" /c/Projects/CLionProjects/ANSCORE/engines/TensorRTAPI/include/engine/*.h /c/Projects/CLionProjects/ANSCORE/modules/ANSODEngine/engine.h)",
"Bash(ssh -T git@anscenter.ddns.net -p 2222)",
"Bash(ssh-add -l)"
] ]
} }
} }

View File

@@ -132,6 +132,15 @@ namespace ANSCENTER
AMD_GPU = 3, AMD_GPU = 3,
AUTO_DETECT = 99 // default: hardware auto-detection AUTO_DETECT = 99 // default: hardware auto-detection
}; };
enum Country {
VIETNAM = 0,
CHINA = 1,
AUSTRALIA = 2,
USA = 3,
INDONESIA = 4,
JAPAN = 5
};
enum DetectionType { enum DetectionType {
CLASSIFICATION = 0, CLASSIFICATION = 0,
DETECTION = 1, DETECTION = 1,

View File

@@ -15,14 +15,8 @@
#define MAX_ALPR_FRAME 60 #define MAX_ALPR_FRAME 60
namespace ANSCENTER namespace ANSCENTER
{ {
enum Country { // Country enum is now defined in ANSLicense.h (ANSCENTER namespace)
VIETNAM = 0,
CHINA = 1,
AUSTRALIA = 2,
USA = 3,
INDONESIA = 4,
JAPAN =5
};
class ALPRChecker { class ALPRChecker {
private: private:
int maxFrames; int maxFrames;

View File

@@ -298,11 +298,11 @@ namespace ANSCENTER {
void ANSOCRBase::SetOCRMode(OCRMode mode) { _ocrMode = mode; } void ANSOCRBase::SetOCRMode(OCRMode mode) { _ocrMode = mode; }
OCRMode ANSOCRBase::GetOCRMode() const { return _ocrMode; } OCRMode ANSOCRBase::GetOCRMode() const { return _ocrMode; }
void ANSOCRBase::SetALPRCountry(ALPRCountry country) { void ANSOCRBase::SetCountry(Country country) {
_alprCountry = country; _alprCountry = country;
LoadDefaultFormats(country); LoadDefaultFormats(country);
} }
ALPRCountry ANSOCRBase::GetALPRCountry() const { return _alprCountry; } Country ANSOCRBase::GetCountry() const { return _alprCountry; }
void ANSOCRBase::SetALPRFormat(const ALPRPlateFormat& format) { void ANSOCRBase::SetALPRFormat(const ALPRPlateFormat& format) {
_alprFormats.clear(); _alprFormats.clear();
_alprFormats.push_back(format); _alprFormats.push_back(format);
@@ -313,12 +313,12 @@ namespace ANSCENTER {
void ANSOCRBase::ClearALPRFormats() { _alprFormats.clear(); } void ANSOCRBase::ClearALPRFormats() { _alprFormats.clear(); }
const std::vector<ALPRPlateFormat>& ANSOCRBase::GetALPRFormats() const { return _alprFormats; } const std::vector<ALPRPlateFormat>& ANSOCRBase::GetALPRFormats() const { return _alprFormats; }
void ANSOCRBase::LoadDefaultFormats(ALPRCountry country) { void ANSOCRBase::LoadDefaultFormats(Country country) {
_alprFormats.clear(); _alprFormats.clear();
if (country == ALPR_JAPAN) { if (country == JAPAN) {
ALPRPlateFormat fmt; ALPRPlateFormat fmt;
fmt.name = "JAPAN_STANDARD"; fmt.name = "JAPAN_STANDARD";
fmt.country = ALPR_JAPAN; fmt.country = JAPAN;
fmt.numRows = 2; fmt.numRows = 2;
fmt.rowSplitThreshold = 0.3f; fmt.rowSplitThreshold = 0.3f;
@@ -832,13 +832,16 @@ namespace ANSCENTER {
auto& jsonResults = root["results"] = nlohmann::json::array(); auto& jsonResults = root["results"] = nlohmann::json::array();
for (const auto& res : results) { for (const auto& res : results) {
// Build extra_info as JSON string with ALPR parts
nlohmann::json alprInfo; nlohmann::json alprInfo;
alprInfo["valid"] = res.valid; alprInfo["valid"] = res.valid;
alprInfo["format"] = res.formatName; alprInfo["format"] = res.formatName;
for (const auto& part : res.parts) { for (const auto& part : res.parts) {
alprInfo[part.first] = part.second; alprInfo[part.first] = part.second;
} }
std::string extraInfoStr = alprInfo.dump();
// Use the same field layout as OCRDetectionToJsonString
jsonResults.push_back({ jsonResults.push_back({
{"class_id", "0"}, {"class_id", "0"},
{"track_id", "0"}, {"track_id", "0"},
@@ -849,11 +852,10 @@ namespace ANSCENTER {
{"width", std::to_string(res.plateBox.width)}, {"width", std::to_string(res.plateBox.width)},
{"height", std::to_string(res.plateBox.height)}, {"height", std::to_string(res.plateBox.height)},
{"mask", ""}, {"mask", ""},
{"extra_info", ""}, {"extra_info", extraInfoStr},
{"camera_id", ""}, {"camera_id", ""},
{"polygon", ""}, {"polygon", ""},
{"kps", ""}, {"kps", ""}
{"alpr_info", alprInfo}
}); });
} }
return root.dump(); return root.dump();

View File

@@ -19,15 +19,6 @@ namespace ANSCENTER {
OCR_ALPR = 1 OCR_ALPR = 1
}; };
enum ALPRCountry {
ALPR_JAPAN = 0,
ALPR_VIETNAM = 1,
ALPR_CHINA = 2,
ALPR_USA = 3,
ALPR_AUSTRALIA = 4,
ALPR_CUSTOM = 99
};
enum ALPRCharClass { enum ALPRCharClass {
CHAR_DIGIT = 0, CHAR_DIGIT = 0,
CHAR_LATIN_ALPHA = 1, CHAR_LATIN_ALPHA = 1,
@@ -53,7 +44,7 @@ namespace ANSCENTER {
struct ALPRPlateFormat { struct ALPRPlateFormat {
std::string name; std::string name;
ALPRCountry country = ALPR_JAPAN; Country country = JAPAN;
int numRows = 2; int numRows = 2;
std::vector<ALPRZone> zones; std::vector<ALPRZone> zones;
float rowSplitThreshold = 0.3f; float rowSplitThreshold = 0.3f;
@@ -152,7 +143,7 @@ namespace ANSCENTER {
// ALPR settings // ALPR settings
OCRMode _ocrMode = OCR_GENERAL; OCRMode _ocrMode = OCR_GENERAL;
ALPRCountry _alprCountry = ALPR_JAPAN; Country _alprCountry = JAPAN;
std::vector<ALPRPlateFormat> _alprFormats; std::vector<ALPRPlateFormat> _alprFormats;
void CheckLicense(); void CheckLicense();
@@ -171,12 +162,12 @@ namespace ANSCENTER {
// ALPR configuration methods // ALPR configuration methods
void SetOCRMode(OCRMode mode); void SetOCRMode(OCRMode mode);
OCRMode GetOCRMode() const; OCRMode GetOCRMode() const;
void SetALPRCountry(ALPRCountry country); void SetCountry(Country country);
ALPRCountry GetALPRCountry() const; Country GetCountry() const;
void SetALPRFormat(const ALPRPlateFormat& format); void SetALPRFormat(const ALPRPlateFormat& format);
void AddALPRFormat(const ALPRPlateFormat& format); void AddALPRFormat(const ALPRPlateFormat& format);
void ClearALPRFormats(); void ClearALPRFormats();
void LoadDefaultFormats(ALPRCountry country); void LoadDefaultFormats(Country country);
const std::vector<ALPRPlateFormat>& GetALPRFormats() const; const std::vector<ALPRPlateFormat>& GetALPRFormats() const;
~ANSOCRBase() { ~ANSOCRBase() {
@@ -249,7 +240,7 @@ extern "C" ANSOCR_API int RunInferencesComplete_LV(ANSCENTER::ANSOCRBase** H
// ALPR configuration API // ALPR configuration API
extern "C" ANSOCR_API int SetANSOCRMode(ANSCENTER::ANSOCRBase** Handle, int ocrMode); extern "C" ANSOCR_API int SetANSOCRMode(ANSCENTER::ANSOCRBase** Handle, int ocrMode);
extern "C" ANSOCR_API int SetANSOCRALPRCountry(ANSCENTER::ANSOCRBase** Handle, int country); extern "C" ANSOCR_API int SetANSOCRCountry(ANSCENTER::ANSOCRBase** Handle, int country);
extern "C" ANSOCR_API int SetANSOCRALPRFormat(ANSCENTER::ANSOCRBase** Handle, const char* formatJson); extern "C" ANSOCR_API int SetANSOCRALPRFormat(ANSCENTER::ANSOCRBase** Handle, const char* formatJson);
// V2 Create / Release — handle as uint64_t by value (no pointer-to-pointer) // V2 Create / Release — handle as uint64_t by value (no pointer-to-pointer)

View File

@@ -374,9 +374,9 @@ extern "C" ANSOCR_API int SetANSOCRMode(ANSCENTER::ANSOCRBase** Handle, int ocrM
return 0; return 0;
} }
extern "C" ANSOCR_API int SetANSOCRALPRCountry(ANSCENTER::ANSOCRBase** Handle, int country) { extern "C" ANSOCR_API int SetANSOCRCountry(ANSCENTER::ANSOCRBase** Handle, int country) {
if (!Handle || !*Handle) return -1; if (!Handle || !*Handle) return -1;
(*Handle)->SetALPRCountry(static_cast<ANSCENTER::ALPRCountry>(country)); (*Handle)->SetCountry(static_cast<ANSCENTER::Country>(country));
return 0; return 0;
} }
@@ -386,7 +386,7 @@ extern "C" ANSOCR_API int SetANSOCRALPRFormat(ANSCENTER::ANSOCRBase** Handle, co
nlohmann::json j = nlohmann::json::parse(formatJson); nlohmann::json j = nlohmann::json::parse(formatJson);
ANSCENTER::ALPRPlateFormat fmt; ANSCENTER::ALPRPlateFormat fmt;
fmt.name = j.value("name", "CUSTOM"); fmt.name = j.value("name", "CUSTOM");
fmt.country = static_cast<ANSCENTER::ALPRCountry>(j.value("country", 99)); fmt.country = static_cast<ANSCENTER::Country>(j.value("country", 99));
fmt.numRows = j.value("num_rows", 2); fmt.numRows = j.value("num_rows", 2);
fmt.rowSplitThreshold = j.value("row_split_threshold", 0.3f); fmt.rowSplitThreshold = j.value("row_split_threshold", 0.3f);

View File

@@ -323,7 +323,7 @@ int TestOCRv5mage() {
// Enable ALPR mode with Japanese plate format // Enable ALPR mode with Japanese plate format
SetANSOCRMode(&infHandle, 1); // OCR_ALPR SetANSOCRMode(&infHandle, 1); // OCR_ALPR
SetANSOCRALPRCountry(&infHandle, 0); // ALPR_JAPAN SetANSOCRCountry(&infHandle, 5); // JAPAN
cv::Mat input = cv::imread(imagePath, cv::IMREAD_COLOR); cv::Mat input = cv::imread(imagePath, cv::IMREAD_COLOR);
if (input.empty()) { if (input.empty()) {
@@ -391,24 +391,28 @@ int TestOCRv5mage() {
cv::rectangle(frame, cv::Rect(x, y, w, h), cv::rectangle(frame, cv::Rect(x, y, w, h),
cv::Scalar(0, 255, 0), boxThickness); cv::Scalar(0, 255, 0), boxThickness);
// Display ALPR structured info if available // Display ALPR structured info from extra_info field
std::string displayText = class_name; std::string displayText = class_name;
if (result.contains("alpr_info")) { std::string extraInfo = result.value("extra_info", "");
const auto& alpr = result["alpr_info"]; if (!extraInfo.empty()) {
std::cout << "\n=== ALPR Result ===" << std::endl; try {
std::cout << " Format: " << alpr.value("format", "") << std::endl; nlohmann::json alpr = nlohmann::json::parse(extraInfo);
std::cout << " Valid: " << (alpr.value("valid", false) ? "YES" : "NO") << std::endl; if (alpr.contains("format")) {
std::cout << " Region: " << alpr.value("region", "") << std::endl; std::cout << "\n=== ALPR Result ===" << std::endl;
std::cout << " Classification: " << alpr.value("classification", "") << std::endl; std::cout << " Format: " << alpr.value("format", "") << std::endl;
std::cout << " Kana: " << alpr.value("kana", "") << std::endl; std::cout << " Valid: " << (alpr.value("valid", false) ? "YES" : "NO") << std::endl;
std::cout << " Designation: " << alpr.value("designation", "") << std::endl; std::cout << " Region: " << alpr.value("region", "") << std::endl;
std::cout << " Full Plate: " << class_name << std::endl; std::cout << " Classification: " << alpr.value("classification", "") << std::endl;
std::cout << " Kana: " << alpr.value("kana", "") << std::endl;
std::cout << " Designation: " << alpr.value("designation", "") << std::endl;
std::cout << " Full Plate: " << class_name << std::endl;
// Build a compact display string for the viewer displayText = alpr.value("region", "") + " " +
displayText = alpr.value("region", "") + " " + alpr.value("classification", "") + " " +
alpr.value("classification", "") + " " + alpr.value("kana", "") + " " +
alpr.value("kana", "") + " " + alpr.value("designation", "");
alpr.value("designation", ""); }
} catch (...) {}
} }
#ifdef WIN32 #ifdef WIN32

View File

@@ -161,7 +161,7 @@ int ANSAWSTest() {
} }
std::cout << "Connected. AWS path style: " << (awsPath ? "true" : "false") << std::endl; std::cout << "Connected. AWS path style: " << (awsPath ? "true" : "false") << std::endl;
// Set authentication // Set authentication (test commit)
std::string accessKey = "AKIAZQ3DPYODSHZCECS4"; std::string accessKey = "AKIAZQ3DPYODSHZCECS4";
std::string secretKey = "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"; std::string secretKey = "ccnISNp05UDRmTP9TLx6kEz7EfnPQqNQXEJOycey";
if (SetAuthenticationANSAWSHandle(&awsHandle, accessKey.c_str(), secretKey.c_str()) != 1) { if (SetAuthenticationANSAWSHandle(&awsHandle, accessKey.c_str(), secretKey.c_str()) != 1) {