Unify country and ocr mode on both ANSOCR and ANSALPR
This commit is contained in:
@@ -5,7 +5,9 @@
|
||||
"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 -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)"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,6 +132,15 @@ namespace ANSCENTER
|
||||
AMD_GPU = 3,
|
||||
AUTO_DETECT = 99 // default: hardware auto-detection
|
||||
};
|
||||
enum Country {
|
||||
VIETNAM = 0,
|
||||
CHINA = 1,
|
||||
AUSTRALIA = 2,
|
||||
USA = 3,
|
||||
INDONESIA = 4,
|
||||
JAPAN = 5
|
||||
};
|
||||
|
||||
enum DetectionType {
|
||||
CLASSIFICATION = 0,
|
||||
DETECTION = 1,
|
||||
|
||||
@@ -15,14 +15,8 @@
|
||||
#define MAX_ALPR_FRAME 60
|
||||
namespace ANSCENTER
|
||||
{
|
||||
enum Country {
|
||||
VIETNAM = 0,
|
||||
CHINA = 1,
|
||||
AUSTRALIA = 2,
|
||||
USA = 3,
|
||||
INDONESIA = 4,
|
||||
JAPAN =5
|
||||
};
|
||||
// Country enum is now defined in ANSLicense.h (ANSCENTER namespace)
|
||||
|
||||
class ALPRChecker {
|
||||
private:
|
||||
int maxFrames;
|
||||
|
||||
@@ -298,11 +298,11 @@ namespace ANSCENTER {
|
||||
|
||||
void ANSOCRBase::SetOCRMode(OCRMode mode) { _ocrMode = mode; }
|
||||
OCRMode ANSOCRBase::GetOCRMode() const { return _ocrMode; }
|
||||
void ANSOCRBase::SetALPRCountry(ALPRCountry country) {
|
||||
void ANSOCRBase::SetCountry(Country country) {
|
||||
_alprCountry = country;
|
||||
LoadDefaultFormats(country);
|
||||
}
|
||||
ALPRCountry ANSOCRBase::GetALPRCountry() const { return _alprCountry; }
|
||||
Country ANSOCRBase::GetCountry() const { return _alprCountry; }
|
||||
void ANSOCRBase::SetALPRFormat(const ALPRPlateFormat& format) {
|
||||
_alprFormats.clear();
|
||||
_alprFormats.push_back(format);
|
||||
@@ -313,12 +313,12 @@ namespace ANSCENTER {
|
||||
void ANSOCRBase::ClearALPRFormats() { _alprFormats.clear(); }
|
||||
const std::vector<ALPRPlateFormat>& ANSOCRBase::GetALPRFormats() const { return _alprFormats; }
|
||||
|
||||
void ANSOCRBase::LoadDefaultFormats(ALPRCountry country) {
|
||||
void ANSOCRBase::LoadDefaultFormats(Country country) {
|
||||
_alprFormats.clear();
|
||||
if (country == ALPR_JAPAN) {
|
||||
if (country == JAPAN) {
|
||||
ALPRPlateFormat fmt;
|
||||
fmt.name = "JAPAN_STANDARD";
|
||||
fmt.country = ALPR_JAPAN;
|
||||
fmt.country = JAPAN;
|
||||
fmt.numRows = 2;
|
||||
fmt.rowSplitThreshold = 0.3f;
|
||||
|
||||
@@ -832,13 +832,16 @@ namespace ANSCENTER {
|
||||
auto& jsonResults = root["results"] = nlohmann::json::array();
|
||||
|
||||
for (const auto& res : results) {
|
||||
// Build extra_info as JSON string with ALPR parts
|
||||
nlohmann::json alprInfo;
|
||||
alprInfo["valid"] = res.valid;
|
||||
alprInfo["format"] = res.formatName;
|
||||
for (const auto& part : res.parts) {
|
||||
alprInfo[part.first] = part.second;
|
||||
}
|
||||
std::string extraInfoStr = alprInfo.dump();
|
||||
|
||||
// Use the same field layout as OCRDetectionToJsonString
|
||||
jsonResults.push_back({
|
||||
{"class_id", "0"},
|
||||
{"track_id", "0"},
|
||||
@@ -849,11 +852,10 @@ namespace ANSCENTER {
|
||||
{"width", std::to_string(res.plateBox.width)},
|
||||
{"height", std::to_string(res.plateBox.height)},
|
||||
{"mask", ""},
|
||||
{"extra_info", ""},
|
||||
{"extra_info", extraInfoStr},
|
||||
{"camera_id", ""},
|
||||
{"polygon", ""},
|
||||
{"kps", ""},
|
||||
{"alpr_info", alprInfo}
|
||||
{"kps", ""}
|
||||
});
|
||||
}
|
||||
return root.dump();
|
||||
|
||||
@@ -19,15 +19,6 @@ namespace ANSCENTER {
|
||||
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 {
|
||||
CHAR_DIGIT = 0,
|
||||
CHAR_LATIN_ALPHA = 1,
|
||||
@@ -53,7 +44,7 @@ namespace ANSCENTER {
|
||||
|
||||
struct ALPRPlateFormat {
|
||||
std::string name;
|
||||
ALPRCountry country = ALPR_JAPAN;
|
||||
Country country = JAPAN;
|
||||
int numRows = 2;
|
||||
std::vector<ALPRZone> zones;
|
||||
float rowSplitThreshold = 0.3f;
|
||||
@@ -152,7 +143,7 @@ namespace ANSCENTER {
|
||||
|
||||
// ALPR settings
|
||||
OCRMode _ocrMode = OCR_GENERAL;
|
||||
ALPRCountry _alprCountry = ALPR_JAPAN;
|
||||
Country _alprCountry = JAPAN;
|
||||
std::vector<ALPRPlateFormat> _alprFormats;
|
||||
|
||||
void CheckLicense();
|
||||
@@ -171,12 +162,12 @@ namespace ANSCENTER {
|
||||
// ALPR configuration methods
|
||||
void SetOCRMode(OCRMode mode);
|
||||
OCRMode GetOCRMode() const;
|
||||
void SetALPRCountry(ALPRCountry country);
|
||||
ALPRCountry GetALPRCountry() const;
|
||||
void SetCountry(Country country);
|
||||
Country GetCountry() const;
|
||||
void SetALPRFormat(const ALPRPlateFormat& format);
|
||||
void AddALPRFormat(const ALPRPlateFormat& format);
|
||||
void ClearALPRFormats();
|
||||
void LoadDefaultFormats(ALPRCountry country);
|
||||
void LoadDefaultFormats(Country country);
|
||||
const std::vector<ALPRPlateFormat>& GetALPRFormats() const;
|
||||
|
||||
~ANSOCRBase() {
|
||||
@@ -249,7 +240,7 @@ extern "C" ANSOCR_API int RunInferencesComplete_LV(ANSCENTER::ANSOCRBase** H
|
||||
|
||||
// ALPR configuration API
|
||||
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);
|
||||
|
||||
// V2 Create / Release — handle as uint64_t by value (no pointer-to-pointer)
|
||||
|
||||
@@ -374,9 +374,9 @@ extern "C" ANSOCR_API int SetANSOCRMode(ANSCENTER::ANSOCRBase** Handle, int ocrM
|
||||
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;
|
||||
(*Handle)->SetALPRCountry(static_cast<ANSCENTER::ALPRCountry>(country));
|
||||
(*Handle)->SetCountry(static_cast<ANSCENTER::Country>(country));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -386,7 +386,7 @@ extern "C" ANSOCR_API int SetANSOCRALPRFormat(ANSCENTER::ANSOCRBase** Handle, co
|
||||
nlohmann::json j = nlohmann::json::parse(formatJson);
|
||||
ANSCENTER::ALPRPlateFormat fmt;
|
||||
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.rowSplitThreshold = j.value("row_split_threshold", 0.3f);
|
||||
|
||||
|
||||
@@ -323,7 +323,7 @@ int TestOCRv5mage() {
|
||||
|
||||
// Enable ALPR mode with Japanese plate format
|
||||
SetANSOCRMode(&infHandle, 1); // OCR_ALPR
|
||||
SetANSOCRALPRCountry(&infHandle, 0); // ALPR_JAPAN
|
||||
SetANSOCRCountry(&infHandle, 5); // JAPAN
|
||||
|
||||
cv::Mat input = cv::imread(imagePath, cv::IMREAD_COLOR);
|
||||
if (input.empty()) {
|
||||
@@ -391,24 +391,28 @@ int TestOCRv5mage() {
|
||||
cv::rectangle(frame, cv::Rect(x, y, w, h),
|
||||
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;
|
||||
if (result.contains("alpr_info")) {
|
||||
const auto& alpr = result["alpr_info"];
|
||||
std::cout << "\n=== ALPR Result ===" << std::endl;
|
||||
std::cout << " Format: " << alpr.value("format", "") << std::endl;
|
||||
std::cout << " Valid: " << (alpr.value("valid", false) ? "YES" : "NO") << std::endl;
|
||||
std::cout << " Region: " << alpr.value("region", "") << 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;
|
||||
std::string extraInfo = result.value("extra_info", "");
|
||||
if (!extraInfo.empty()) {
|
||||
try {
|
||||
nlohmann::json alpr = nlohmann::json::parse(extraInfo);
|
||||
if (alpr.contains("format")) {
|
||||
std::cout << "\n=== ALPR Result ===" << std::endl;
|
||||
std::cout << " Format: " << alpr.value("format", "") << std::endl;
|
||||
std::cout << " Valid: " << (alpr.value("valid", false) ? "YES" : "NO") << std::endl;
|
||||
std::cout << " Region: " << alpr.value("region", "") << 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", "") + " " +
|
||||
alpr.value("classification", "") + " " +
|
||||
alpr.value("kana", "") + " " +
|
||||
alpr.value("designation", "");
|
||||
displayText = alpr.value("region", "") + " " +
|
||||
alpr.value("classification", "") + " " +
|
||||
alpr.value("kana", "") + " " +
|
||||
alpr.value("designation", "");
|
||||
}
|
||||
} catch (...) {}
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
@@ -161,7 +161,7 @@ int ANSAWSTest() {
|
||||
}
|
||||
std::cout << "Connected. AWS path style: " << (awsPath ? "true" : "false") << std::endl;
|
||||
|
||||
// Set authentication
|
||||
// Set authentication (test commit)
|
||||
std::string accessKey = "AKIAZQ3DPYODSHZCECS4";
|
||||
std::string secretKey = "ccnISNp05UDRmTP9TLx6kEz7EfnPQqNQXEJOycey";
|
||||
if (SetAuthenticationANSAWSHandle(&awsHandle, accessKey.c_str(), secretKey.c_str()) != 1) {
|
||||
|
||||
Reference in New Issue
Block a user