From 3fdb150b2f50a1a14d0e3041adbb869cb4146ae7 Mon Sep 17 00:00:00 2001 From: Matt Hill Date: Sat, 11 Jul 2015 15:40:48 -0400 Subject: [PATCH 1/4] Checking for minimum tesseract version, rather than an explicit match --- src/openalpr/ocr.cpp | 9 ++++----- src/openalpr/ocr.h | 1 + src/openalpr/support/CMakeLists.txt | 1 + src/openalpr/support/version.cpp | 30 +++++++++++++++++++++++++++++ src/openalpr/support/version.h | 17 ++++++++++++++++ 5 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 src/openalpr/support/version.cpp create mode 100644 src/openalpr/support/version.h diff --git a/src/openalpr/ocr.cpp b/src/openalpr/ocr.cpp index 2409944..c589b70 100644 --- a/src/openalpr/ocr.cpp +++ b/src/openalpr/ocr.cpp @@ -29,15 +29,14 @@ namespace alpr OCR::OCR(Config* config) : postProcessor(config) { - const string EXPECTED_TESSERACT_VERSION = "3.03"; + const string MINIMUM_TESSERACT_VERSION = "3.03"; this->config = config; - - - if (startsWith(tesseract.Version(), EXPECTED_TESSERACT_VERSION) == false) + + if (cmpVersion(tesseract.Version(), MINIMUM_TESSERACT_VERSION.c_str()) < 0) { std::cerr << "Warning: You are running an unsupported version of Tesseract." << endl; - std::cerr << "Expecting version " << EXPECTED_TESSERACT_VERSION << ", your version is: " << tesseract.Version() << endl; + std::cerr << "Expecting at least " << MINIMUM_TESSERACT_VERSION << ", your version is: " << tesseract.Version() << endl; } // Tesseract requires the prefix directory to be set as an env variable diff --git a/src/openalpr/ocr.h b/src/openalpr/ocr.h index 24b3a76..a69ca33 100644 --- a/src/openalpr/ocr.h +++ b/src/openalpr/ocr.h @@ -31,6 +31,7 @@ #include "constants.h" #include "opencv2/imgproc/imgproc.hpp" #include "support/filesystem.h" +#include "support/version.h" #include "tesseract/baseapi.h" diff --git a/src/openalpr/support/CMakeLists.txt b/src/openalpr/support/CMakeLists.txt index f2db822..54b0a36 100644 --- a/src/openalpr/support/CMakeLists.txt +++ b/src/openalpr/support/CMakeLists.txt @@ -6,6 +6,7 @@ set(support_source_files tinythread.cpp platform.cpp utf8.cpp + version.cpp ) set(regex_source_files diff --git a/src/openalpr/support/version.cpp b/src/openalpr/support/version.cpp new file mode 100644 index 0000000..b82a557 --- /dev/null +++ b/src/openalpr/support/version.cpp @@ -0,0 +1,30 @@ +#include "version.h" + + +#include +#include +#include +int cmpVersion(const char *v1, const char *v2) +{ + int i; + int oct_v1[4], oct_v2[4]; + + for (int i = 0; i < 4; i++) + { + oct_v1[i] = 0; + oct_v2[i] = 0; + } + + sscanf(v1, "%d.%d.%d.%d", &oct_v1[0], &oct_v1[1], &oct_v1[2], &oct_v1[3]); + sscanf(v2, "%d.%d.%d.%d", &oct_v2[0], &oct_v2[1], &oct_v2[2], &oct_v2[3]); + + + for (i = 0; i < 4; i++) { + if (oct_v1[i] > oct_v2[i]) + return 1; + else if (oct_v1[i] < oct_v2[i]) + return -1; + } + + return 0; +} \ No newline at end of file diff --git a/src/openalpr/support/version.h b/src/openalpr/support/version.h new file mode 100644 index 0000000..94b56dd --- /dev/null +++ b/src/openalpr/support/version.h @@ -0,0 +1,17 @@ +#ifndef OPENALPR_VERSION_H +#define OPENALPR_VERSION_H + +#include +#include + +/* + * return 1 if v1 > v2 + * return 0 if v1 = v2 + * return -1 if v1 < v2 + */ + +int cmpVersion(const char *v1, const char *v2); + + +#endif /* OPENALPR_VERSION_H */ + From b77bea2f1de53add7a4c1ce4ae609b909ad65540 Mon Sep 17 00:00:00 2001 From: Matt Hill Date: Sun, 12 Jul 2015 09:11:54 -0400 Subject: [PATCH 2/4] Added library initialization time. Resolves issue #161 --- src/openalpr/alpr_impl.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/openalpr/alpr_impl.cpp b/src/openalpr/alpr_impl.cpp index 0d334b6..fc8ca37 100644 --- a/src/openalpr/alpr_impl.cpp +++ b/src/openalpr/alpr_impl.cpp @@ -29,6 +29,10 @@ namespace alpr { AlprImpl::AlprImpl(const std::string country, const std::string configFile, const std::string runtimeDir) { + + timespec startTime; + getTimeMonotonic(&startTime); + config = new Config(country, configFile, runtimeDir); plateDetector = ALPR_NULL_PTR; @@ -51,7 +55,12 @@ namespace alpr setDefaultRegion(""); prewarp = new PreWarp(config); - + + timespec endTime; + getTimeMonotonic(&endTime); + if (config->debugTiming) + cout << "OpenALPR Initialization Time: " << diffclock(startTime, endTime) << "ms." << endl; + } AlprImpl::~AlprImpl() { @@ -559,12 +568,22 @@ namespace alpr void AlprImpl::setDetectRegion(bool detectRegion) { + this->detectRegion = detectRegion; if (detectRegion && this->stateIdentifier == NULL) { + timespec startTime; + getTimeMonotonic(&startTime); + this->stateIdentifier = new StateIdentifier(this->config); + + timespec endTime; + getTimeMonotonic(&endTime); + if (config->debugTiming) + cout << "State Identification Initialization Time: " << diffclock(startTime, endTime) << "ms." << endl; } + } void AlprImpl::setTopN(int topn) { From d32796ef968322694bd2897d4ca869b10e320c48 Mon Sep 17 00:00:00 2001 From: Matthew Hill Date: Sun, 12 Jul 2015 21:10:41 -0400 Subject: [PATCH 3/4] Update README.md --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 0fa2cf9..d250fd2 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,11 @@ Install OpenALPR on Ubuntu 14.04 x64 with the following commands: sudo apt-get update sudo apt-get install openalpr openalpr-daemon openalpr-utils libopenalpr-dev +Integrating the Library +----------------------- + +OpenALPR is written in C++ and has bindings in C#, Python, and Java. Please see this guide for examples showing how to run OpenALPR in your application: https://github.com/openalpr/openalpr/wiki/Integrating-OpenALPR + Compiling ----------- From 4a3cd82b7dc07d81bc8dfc7af4fe2d0d6ef6bd95 Mon Sep 17 00:00:00 2001 From: Matt Hill Date: Sun, 12 Jul 2015 21:26:35 -0400 Subject: [PATCH 4/4] Fixed setDebug functiont to apply correct value --- src/openalpr/config.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/openalpr/config.cpp b/src/openalpr/config.cpp index 920f08f..17f4846 100644 --- a/src/openalpr/config.cpp +++ b/src/openalpr/config.cpp @@ -253,17 +253,17 @@ namespace alpr void Config::setDebug(bool value) { - debugGeneral = !value; - debugTiming = !value; - debugStateId = !value; - debugPlateLines = !value; - debugPlateCorners = !value; - debugCharSegmenter = !value; - debugCharAnalysis = !value; - debugColorFiler = !value; - debugOcr = !value; - debugPostProcess = !value; - debugPauseOnFrame = !value; + debugGeneral = value; + debugTiming = value; + debugStateId = value; + debugPlateLines = value; + debugPlateCorners = value; + debugCharSegmenter = value; + debugCharAnalysis = value; + debugColorFiler = value; + debugOcr = value; + debugPostProcess = value; + debugPauseOnFrame = value; }