mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-07 03:32:56 +08:00
Remove trailing whitespace
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
/*
|
||||
* Copyright (c) 2013 New Designs Unlimited, LLC
|
||||
* Opensource Automated License Plate Recognition [http://www.openalpr.com]
|
||||
*
|
||||
*
|
||||
* This file is part of OpenAlpr.
|
||||
*
|
||||
*
|
||||
* OpenAlpr is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License
|
||||
* version 3 as published by the Free Software Foundation
|
||||
*
|
||||
* it under the terms of the GNU Affero General Public License
|
||||
* version 3 as published by the Free Software Foundation
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
@@ -26,32 +26,32 @@ AlprImpl::AlprImpl(const std::string country, const std::string runtimeDir)
|
||||
plateDetector = new RegionDetector(config);
|
||||
stateIdentifier = new StateIdentifier(config);
|
||||
ocr = new OCR(config);
|
||||
|
||||
|
||||
this->detectRegion = DEFAULT_DETECT_REGION;
|
||||
this->topN = DEFAULT_TOPN;
|
||||
this->defaultRegion = "";
|
||||
|
||||
|
||||
if (config->opencl_enabled)
|
||||
{
|
||||
|
||||
|
||||
cv::ocl::PlatformsInfo platinfo;
|
||||
cv::ocl::getOpenCLPlatforms(platinfo);
|
||||
|
||||
|
||||
for (int i = 0; i < platinfo.size(); i++)
|
||||
{
|
||||
std::cout << platinfo[i]->platformName << std::endl;
|
||||
}
|
||||
|
||||
|
||||
cv::ocl::DevicesInfo devices;
|
||||
cv::ocl::getOpenCLDevices(devices, cv::ocl::CVCL_DEVICE_TYPE_CPU);
|
||||
|
||||
|
||||
for (int i = 0; i < devices.size(); i++)
|
||||
std:: cout << devices[i]->deviceName << std::endl;
|
||||
|
||||
|
||||
if (devices.size() > 0)
|
||||
{
|
||||
cv::ocl::setDevice(devices[0]);
|
||||
|
||||
|
||||
cout << "Using OpenCL Device: " << devices[0]->deviceName << endl;
|
||||
}
|
||||
else
|
||||
@@ -73,9 +73,9 @@ std::vector<AlprResult> AlprImpl::recognize(cv::Mat img)
|
||||
{
|
||||
timespec startTime;
|
||||
getTime(&startTime);
|
||||
|
||||
|
||||
vector<AlprResult> response;
|
||||
|
||||
|
||||
|
||||
vector<Rect> plateRegions = plateDetector->detect(img);
|
||||
|
||||
@@ -86,24 +86,24 @@ std::vector<AlprResult> AlprImpl::recognize(cv::Mat img)
|
||||
{
|
||||
timespec platestarttime;
|
||||
getTime(&platestarttime);
|
||||
|
||||
|
||||
LicensePlateCandidate lp(img, plateRegions[i], config);
|
||||
|
||||
|
||||
lp.recognize();
|
||||
|
||||
|
||||
|
||||
if (lp.confidence > 10)
|
||||
{
|
||||
AlprResult plateResult;
|
||||
plateResult.region = defaultRegion;
|
||||
plateResult.regionConfidence = 0;
|
||||
|
||||
|
||||
for (int pointidx = 0; pointidx < 4; pointidx++)
|
||||
{
|
||||
plateResult.plate_points[pointidx].x = (int) lp.plateCorners[pointidx].x;
|
||||
plateResult.plate_points[pointidx].y = (int) lp.plateCorners[pointidx].y;
|
||||
}
|
||||
|
||||
|
||||
if (detectRegion)
|
||||
{
|
||||
char statecode[4];
|
||||
@@ -113,26 +113,26 @@ std::vector<AlprResult> AlprImpl::recognize(cv::Mat img)
|
||||
plateResult.region = statecode;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
ocr->performOCR(lp.charSegmenter->getThresholds(), lp.charSegmenter->characters);
|
||||
|
||||
|
||||
ocr->postProcessor->analyze(plateResult.region, topN);
|
||||
|
||||
//plateResult.characters = ocr->postProcessor->bestChars;
|
||||
const vector<PPResult> ppResults = ocr->postProcessor->getResults();
|
||||
|
||||
|
||||
int bestPlateIndex = 0;
|
||||
|
||||
|
||||
for (int pp = 0; pp < ppResults.size(); pp++)
|
||||
{
|
||||
if (pp >= topN)
|
||||
break;
|
||||
|
||||
|
||||
// Set our "best plate" match to either the first entry, or the first entry with a postprocessor template match
|
||||
if (bestPlateIndex == 0 && ppResults[pp].matchesTemplate)
|
||||
bestPlateIndex = pp;
|
||||
|
||||
|
||||
if (ppResults[pp].letters.size() >= config->postProcessMinCharacters &&
|
||||
ppResults[pp].letters.size() <= config->postProcessMaxCharacters)
|
||||
{
|
||||
@@ -144,32 +144,32 @@ std::vector<AlprResult> AlprImpl::recognize(cv::Mat img)
|
||||
}
|
||||
}
|
||||
plateResult.result_count = plateResult.topNPlates.size();
|
||||
|
||||
|
||||
if (plateResult.topNPlates.size() > 0)
|
||||
plateResult.bestPlate = plateResult.topNPlates[bestPlateIndex];
|
||||
|
||||
|
||||
timespec plateEndTime;
|
||||
getTime(&plateEndTime);
|
||||
plateResult.processing_time_ms = diffclock(platestarttime, plateEndTime);
|
||||
|
||||
|
||||
if (plateResult.result_count > 0)
|
||||
response.push_back(plateResult);
|
||||
|
||||
|
||||
if (config->debugGeneral)
|
||||
{
|
||||
rectangle(img, plateRegions[i], Scalar(0, 255, 0), 2);
|
||||
for (int z = 0; z < 4; z++)
|
||||
line(img, lp.plateCorners[z], lp.plateCorners[(z + 1) % 4], Scalar(255,0,255), 2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (config->debugGeneral)
|
||||
rectangle(img, plateRegions[i], Scalar(0, 0, 255), 2);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (config->debugTiming)
|
||||
@@ -178,7 +178,7 @@ std::vector<AlprResult> AlprImpl::recognize(cv::Mat img)
|
||||
getTime(&endTime);
|
||||
cout << "Total Time to process image: " << diffclock(startTime, endTime) << "ms." << endl;
|
||||
}
|
||||
|
||||
|
||||
if (config->debugGeneral && config->debugShowImages)
|
||||
{
|
||||
displayImage(config, "Main Image", img);
|
||||
@@ -191,21 +191,21 @@ std::vector<AlprResult> AlprImpl::recognize(cv::Mat img)
|
||||
|
||||
string AlprImpl::toJson(const vector< AlprResult > results)
|
||||
{
|
||||
cJSON *root = cJSON_CreateArray();
|
||||
|
||||
cJSON *root = cJSON_CreateArray();
|
||||
|
||||
for (int i = 0; i < results.size(); i++)
|
||||
{
|
||||
cJSON *resultObj = createJsonObj( &results[i] );
|
||||
cJSON_AddItemToArray(root, resultObj);
|
||||
}
|
||||
|
||||
|
||||
// Print the JSON object to a string and return
|
||||
char *out;
|
||||
out=cJSON_PrintUnformatted(root);
|
||||
cJSON_Delete(root);
|
||||
|
||||
|
||||
string response(out);
|
||||
|
||||
|
||||
free(out);
|
||||
return response;
|
||||
}
|
||||
@@ -215,18 +215,18 @@ string AlprImpl::toJson(const vector< AlprResult > results)
|
||||
cJSON* AlprImpl::createJsonObj(const AlprResult* result)
|
||||
{
|
||||
cJSON *root, *coords, *candidates;
|
||||
|
||||
root=cJSON_CreateObject();
|
||||
|
||||
|
||||
root=cJSON_CreateObject();
|
||||
|
||||
cJSON_AddStringToObject(root,"plate", result->bestPlate.characters.c_str());
|
||||
cJSON_AddNumberToObject(root,"confidence", result->bestPlate.overall_confidence);
|
||||
cJSON_AddNumberToObject(root,"matches_template", result->bestPlate.matches_template);
|
||||
|
||||
|
||||
cJSON_AddStringToObject(root,"region", result->region.c_str());
|
||||
cJSON_AddNumberToObject(root,"region_confidence", result->regionConfidence);
|
||||
|
||||
|
||||
cJSON_AddNumberToObject(root,"processing_time_ms", result->processing_time_ms);
|
||||
|
||||
|
||||
cJSON_AddItemToObject(root, "coordinates", coords=cJSON_CreateArray());
|
||||
for (int i=0;i<4;i++)
|
||||
{
|
||||
@@ -237,8 +237,8 @@ cJSON* AlprImpl::createJsonObj(const AlprResult* result)
|
||||
|
||||
cJSON_AddItemToArray(coords, coords_object);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
cJSON_AddItemToObject(root, "candidates", candidates=cJSON_CreateArray());
|
||||
for (int i = 0; i < result->topNPlates.size(); i++)
|
||||
{
|
||||
@@ -250,7 +250,7 @@ cJSON* AlprImpl::createJsonObj(const AlprResult* result)
|
||||
|
||||
cJSON_AddItemToArray(candidates, candidate_object);
|
||||
}
|
||||
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
@@ -267,4 +267,3 @@ void AlprImpl::setDefaultRegion(string region)
|
||||
{
|
||||
this->defaultRegion = region;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user