From 61f37ba596949e87e29d4fc3b00f9bb5fca1ef65 Mon Sep 17 00:00:00 2001 From: Matt Hill Date: Thu, 24 Sep 2015 22:12:31 -0400 Subject: [PATCH] Added a must_match_pattern config option. When a text pattern is available, all non-matching values will be disregarded. --- config/openalpr.conf.in | 4 ++++ src/openalpr/config.cpp | 2 ++ src/openalpr/config.h | 2 ++ src/openalpr/postprocess/postprocess.cpp | 14 +++++++++++--- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/config/openalpr.conf.in b/config/openalpr.conf.in index fd8a97e..3507682 100644 --- a/config/openalpr.conf.in +++ b/config/openalpr.conf.in @@ -42,6 +42,10 @@ max_detection_input_height = 720 ; morphcpu - Experimental detector that detects white rectangles in an image. Does not require training. detector = lbpcpu +; If set to true, all results must match a postprocess text pattern if a pattern is available. +; If not, the result is disqualified. +must_match_pattern = 0 + ; Bypasses plate detection. If this is set to 1, the library assumes that each region provided is a likely plate area. skip_detection = 0 diff --git a/src/openalpr/config.cpp b/src/openalpr/config.cpp index f4794b0..4ce8fbb 100644 --- a/src/openalpr/config.cpp +++ b/src/openalpr/config.cpp @@ -176,6 +176,8 @@ namespace alpr maxDetectionInputWidth = getInt(ini, "", "max_detection_input_width", 1280); maxDetectionInputHeight = getInt(ini, "", "max_detection_input_height", 768); + mustMatchPattern = getBoolean(ini, "", "must_match_pattern", false); + skipDetection = getBoolean(ini, "", "skip_detection", false); prewarp = getString(ini, "", "prewarp", ""); diff --git a/src/openalpr/config.h b/src/openalpr/config.h index 72deb78..47ef75e 100644 --- a/src/openalpr/config.h +++ b/src/openalpr/config.h @@ -104,6 +104,8 @@ namespace alpr std::string ocrLanguage; int ocrMinFontSize; + bool mustMatchPattern; + float postProcessMinConfidence; float postProcessConfidenceSkipLevel; unsigned int postProcessMinCharacters; diff --git a/src/openalpr/postprocess/postprocess.cpp b/src/openalpr/postprocess/postprocess.cpp index 6580d1d..1a66b33 100644 --- a/src/openalpr/postprocess/postprocess.cpp +++ b/src/openalpr/postprocess/postprocess.cpp @@ -381,9 +381,17 @@ namespace alpr if (allPossibilitiesLetters.end() != allPossibilitiesLetters.find(possibility.letters)) return false; - allPossibilities.push_back(possibility); - allPossibilitiesLetters.insert(possibility.letters); - return true; + // If mustMatchPattern is toggled in the config and a template is provided, + // only include this result if there is a pattern match + if (!config->mustMatchPattern || templateregion.size() == 0 || + (config->mustMatchPattern && possibility.matchesTemplate)) + { + allPossibilities.push_back(possibility); + allPossibilitiesLetters.insert(possibility.letters); + return true; + } + + return false; } std::vector PostProcess::getPatterns() {