Added setCountry function to main API.

This allows the country to be changed without reloading the library and runtime_data
This commit is contained in:
Matt Hill
2016-02-14 15:58:04 -05:00
parent bc6e49b546
commit eb2954e49f
6 changed files with 83 additions and 31 deletions

View File

@@ -45,19 +45,7 @@ namespace alpr
return;
}
for (unsigned int i = 0; i < config->loaded_countries.size(); i++)
{
config->setCountry(config->loaded_countries[i]);
AlprRecognizers recognizer;
recognizer.plateDetector = createDetector(config);
recognizer.ocr = new OCR(config);
recognizer.stateDetector = new StateDetector(this->config->country, this->config->config_file_path, this->config->runtimeBaseDir);
recognizers[config->country] = recognizer;
}
loadRecognizers();
setNumThreads(0);
@@ -666,6 +654,11 @@ namespace alpr
return allResults;
}
void AlprImpl::setCountry(std::string country) {
config->load_countries(country);
loadRecognizers();
}
void AlprImpl::setDetectRegion(bool detectRegion)
{
@@ -691,6 +684,28 @@ namespace alpr
return ss.str();
}
void AlprImpl::loadRecognizers() {
for (unsigned int i = 0; i < config->loaded_countries.size(); i++)
{
config->setCountry(config->loaded_countries[i]);
if (recognizers.find(config->country) == recognizers.end())
{
// Country training data has not already been loaded. Load it.
AlprRecognizers recognizer;
recognizer.plateDetector = createDetector(config);
recognizer.ocr = new OCR(config);
recognizer.stateDetector = new StateDetector(this->config->country, this->config->config_file_path, this->config->runtimeBaseDir);
recognizers[config->country] = recognizer;
}
}
}
cv::Mat AlprImpl::getCharacterTransformMatrix(PipelineData* pipeline_data ) {
std::vector<Point2f> crop_corners;
crop_corners.push_back(Point2f(0,0));