diff --git a/runtime_data/config/au.conf b/runtime_data/config/au.conf index d3fd4a9..d2b779c 100644 --- a/runtime_data/config/au.conf +++ b/runtime_data/config/au.conf @@ -33,4 +33,9 @@ ocr_language = lau ; Override for postprocess letters/numbers regex. postprocess_regex_letters = [A-Z] -postprocess_regex_numbers = [0-9] \ No newline at end of file +postprocess_regex_numbers = [0-9] + + +; Whether the plate is always dark letters on light background, light letters on dark background, or both +; value can be either always, never, or auto +invert = auto \ No newline at end of file diff --git a/runtime_data/config/auwide.conf b/runtime_data/config/auwide.conf index 490e7b3..ef01854 100644 --- a/runtime_data/config/auwide.conf +++ b/runtime_data/config/auwide.conf @@ -34,4 +34,9 @@ ocr_language = lau ; Override for postprocess letters/numbers regex. postprocess_regex_letters = [A-Z] -postprocess_regex_numbers = [0-9] \ No newline at end of file +postprocess_regex_numbers = [0-9] + + +; Whether the plate is always dark letters on light background, light letters on dark background, or both +; value can be either always, never, or auto +invert = auto \ No newline at end of file diff --git a/runtime_data/config/eu.conf b/runtime_data/config/eu.conf index b3d3f69..d78be26 100644 --- a/runtime_data/config/eu.conf +++ b/runtime_data/config/eu.conf @@ -35,4 +35,9 @@ ocr_language = leu ; Override for postprocess letters/numbers regex. postprocess_regex_letters = [A-Z] -postprocess_regex_numbers = [0-9] \ No newline at end of file +postprocess_regex_numbers = [0-9] + + +; Whether the plate is always dark letters on light background, light letters on dark background, or both +; value can be either always, never, or auto +invert = auto \ No newline at end of file diff --git a/runtime_data/config/kr.conf b/runtime_data/config/kr.conf index e0ca45f..b9075d5 100644 --- a/runtime_data/config/kr.conf +++ b/runtime_data/config/kr.conf @@ -35,3 +35,7 @@ ocr_language = lkr ; Override for postprocess letters/numbers regex. postprocess_regex_letters = \pL postprocess_regex_numbers = \pN + +; Whether the plate is always dark letters on light background, light letters on dark background, or both +; value can be either always, never, or auto +invert = auto \ No newline at end of file diff --git a/runtime_data/config/us.conf b/runtime_data/config/us.conf index c9f8124..0c6a27d 100644 --- a/runtime_data/config/us.conf +++ b/runtime_data/config/us.conf @@ -33,4 +33,8 @@ ocr_language = lus ; Override for postprocess letters/numbers regex. postprocess_regex_letters = [A-Z] -postprocess_regex_numbers = [0-9] \ No newline at end of file +postprocess_regex_numbers = [0-9] + +; Whether the plate is always dark letters on light background, light letters on dark background, or both +; value can be either always, never, or auto +invert = auto \ No newline at end of file diff --git a/src/openalpr/config.cpp b/src/openalpr/config.cpp index 1e8c99d..da0a9ae 100644 --- a/src/openalpr/config.cpp +++ b/src/openalpr/config.cpp @@ -219,6 +219,24 @@ namespace alpr multiline = getBoolean(ini, "", "multiline", false); + string invert_val = getString(ini, "", "invert", "auto"); + + if (invert_val == "always") + { + auto_invert = false; + always_invert = true; + } + else if (invert_val == "never") + { + auto_invert = false; + always_invert = false; + } + else + { + auto_invert = true; + always_invert = false; + } + plateWidthMM = getFloat(ini, "", "plate_width_mm", 100); plateHeightMM = getFloat(ini, "", "plate_height_mm", 100); diff --git a/src/openalpr/config.h b/src/openalpr/config.h index 3767329..59d6102 100644 --- a/src/openalpr/config.h +++ b/src/openalpr/config.h @@ -54,6 +54,9 @@ namespace alpr bool skipDetection; + bool auto_invert; + bool always_invert; + std::string prewarp; int maxPlateAngleDegrees; diff --git a/src/openalpr/textdetection/characteranalysis.cpp b/src/openalpr/textdetection/characteranalysis.cpp index 653ebb0..59bfbc4 100644 --- a/src/openalpr/textdetection/characteranalysis.cpp +++ b/src/openalpr/textdetection/characteranalysis.cpp @@ -51,6 +51,9 @@ namespace alpr timespec startTime; getTimeMonotonic(&startTime); + if (config->always_invert) + bitwise_not(pipeline_data->crop_gray, pipeline_data->crop_gray); + pipeline_data->clearThresholds(); pipeline_data->thresholds = produceThresholds(pipeline_data->crop_gray, config); @@ -177,7 +180,13 @@ namespace alpr } - pipeline_data->plate_inverted = isPlateInverted(); + if (config->auto_invert) + pipeline_data->plate_inverted = isPlateInverted(); + else + pipeline_data->plate_inverted = config->always_invert; + + if (config->debugGeneral) + cout << "Plate inverted: " << pipeline_data->plate_inverted << endl; if (pipeline_data->textLines.size() > 0)