Unify country and ocr mode on both ANSOCR and ANSALPR
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user