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

@@ -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();