diff --git a/src/openalpr/alpr.cpp b/src/openalpr/alpr.cpp index 5ad39db..a2e4d66 100644 --- a/src/openalpr/alpr.cpp +++ b/src/openalpr/alpr.cpp @@ -91,6 +91,10 @@ namespace alpr impl->setCountry(country); } + void Alpr::setPrewarp(std::string prewarp_config) { + impl->setPrewarp(prewarp_config); + } + void Alpr::setDetectRegion(bool detectRegion) { diff --git a/src/openalpr/alpr.h b/src/openalpr/alpr.h index 43a1725..c34f369 100644 --- a/src/openalpr/alpr.h +++ b/src/openalpr/alpr.h @@ -140,6 +140,9 @@ namespace alpr // Set the country used for plate recognition void setCountry(std::string country); + // Update the prewarp setting without reloading the library + void setPrewarp(std::string prewarp_config); + void setDetectRegion(bool detectRegion); void setTopN(int topN); void setDefaultRegion(std::string region); diff --git a/src/openalpr/alpr_impl.cpp b/src/openalpr/alpr_impl.cpp index d2ec057..f7579f1 100644 --- a/src/openalpr/alpr_impl.cpp +++ b/src/openalpr/alpr_impl.cpp @@ -659,6 +659,11 @@ namespace alpr loadRecognizers(); } + void AlprImpl::setPrewarp(std::string prewarp_config) + { + prewarp->initialize(prewarp_config); + } + void AlprImpl::setDetectRegion(bool detectRegion) { diff --git a/src/openalpr/alpr_impl.h b/src/openalpr/alpr_impl.h index 067598c..15cc029 100644 --- a/src/openalpr/alpr_impl.h +++ b/src/openalpr/alpr_impl.h @@ -93,6 +93,8 @@ namespace alpr AlprFullDetails analyzeSingleCountry(cv::Mat colorImg, cv::Mat grayImg, std::vector regionsOfInterest); void setCountry(std::string country); + void setPrewarp(std::string prewarp_config); + void setDetectRegion(bool detectRegion); void setTopN(int topn); void setDefaultRegion(std::string region); diff --git a/src/openalpr/prewarp.cpp b/src/openalpr/prewarp.cpp index 5b6e960..7a3a137 100644 --- a/src/openalpr/prewarp.cpp +++ b/src/openalpr/prewarp.cpp @@ -28,15 +28,22 @@ using namespace cv; namespace alpr { - PreWarp::PreWarp(Config* config) { + PreWarp::PreWarp(Config* config) + { this->config = config; - - string warp_config = config->prewarp; + initialize(config->prewarp); + } + + + void PreWarp::initialize(std::string prewarp_config) { + + timespec startTime; + getTimeMonotonic(&startTime); // Do a cursory verification based on number of commas - int commacount = count(warp_config.begin(), warp_config.end(), ','); + int commacount = count(prewarp_config.begin(), prewarp_config.end(), ','); - if (warp_config.length() < 4) + if (prewarp_config.length() < 4) { // No config specified. ignore if (this->config->debugPrewarp) @@ -55,10 +62,10 @@ namespace alpr { // Parse the warp_config - int first_comma = warp_config.find(","); + int first_comma = prewarp_config.find(","); - string name = warp_config.substr(0, first_comma); + string name = prewarp_config.substr(0, first_comma); if (name != "planar") { @@ -66,7 +73,7 @@ namespace alpr } else { - stringstream ss(warp_config.substr(first_comma + 1, warp_config.length())); + stringstream ss(prewarp_config.substr(first_comma + 1, prewarp_config.length())); ss >> w; ss.ignore(); @@ -90,9 +97,13 @@ namespace alpr } } + + timespec endTime; + getTimeMonotonic(&endTime); + if (config->debugTiming) + cout << "Prewarp Initialization Time: " << diffclock(startTime, endTime) << "ms." << endl; } - PreWarp::~PreWarp() { } diff --git a/src/openalpr/prewarp.h b/src/openalpr/prewarp.h index 1d298ff..6161682 100644 --- a/src/openalpr/prewarp.h +++ b/src/openalpr/prewarp.h @@ -34,6 +34,8 @@ namespace alpr PreWarp(Config* config); virtual ~PreWarp(); + void initialize(std::string prewarp_config); + cv::Mat warpImage(cv::Mat image); std::vector projectPoints(std::vector points, bool inverse); std::vector projectRects(std::vector rects, int maxWidth, int maxHeight, bool inverse);