Wrapped OpenALPR library in "alpr" namespace. Resolves issue #60.

This commit is contained in:
Matt Hill
2014-10-27 20:12:57 -04:00
parent 83ed86c6b4
commit 85f52a6b8c
79 changed files with 7234 additions and 6968 deletions

View File

@@ -26,101 +26,104 @@
using namespace std;
using namespace cv;
LicensePlateCandidate::LicensePlateCandidate(PipelineData* pipeline_data)
namespace alpr
{
this->pipeline_data = pipeline_data;
this->config = pipeline_data->config;
}
LicensePlateCandidate::~LicensePlateCandidate()
{
delete charSegmenter;
}
// Must delete this pointer in parent class
void LicensePlateCandidate::recognize()
{
charSegmenter = NULL;
pipeline_data->plate_area_confidence = 0;
pipeline_data->isMultiline = config->multiline;
Rect expandedRegion = this->pipeline_data->regionOfInterest;
pipeline_data->crop_gray = Mat(this->pipeline_data->grayImg, expandedRegion);
resize(pipeline_data->crop_gray, pipeline_data->crop_gray, Size(config->templateWidthPx, config->templateHeightPx));
CharacterAnalysis textAnalysis(pipeline_data);
if (textAnalysis.confidence > 10)
LicensePlateCandidate::LicensePlateCandidate(PipelineData* pipeline_data)
{
this->pipeline_data = pipeline_data;
this->config = pipeline_data->config;
EdgeFinder edgeFinder(pipeline_data);
pipeline_data->plate_corners = edgeFinder.findEdgeCorners();
if (edgeFinder.confidence > 0)
}
LicensePlateCandidate::~LicensePlateCandidate()
{
delete charSegmenter;
}
// Must delete this pointer in parent class
void LicensePlateCandidate::recognize()
{
charSegmenter = NULL;
pipeline_data->plate_area_confidence = 0;
pipeline_data->isMultiline = config->multiline;
Rect expandedRegion = this->pipeline_data->regionOfInterest;
pipeline_data->crop_gray = Mat(this->pipeline_data->grayImg, expandedRegion);
resize(pipeline_data->crop_gray, pipeline_data->crop_gray, Size(config->templateWidthPx, config->templateHeightPx));
CharacterAnalysis textAnalysis(pipeline_data);
if (textAnalysis.confidence > 10)
{
timespec startTime;
getTime(&startTime);
EdgeFinder edgeFinder(pipeline_data);
pipeline_data->plate_corners = edgeFinder.findEdgeCorners();
Mat originalCrop = pipeline_data->crop_gray;
Transformation imgTransform(this->pipeline_data->grayImg, pipeline_data->crop_gray, expandedRegion);
Size cropSize = imgTransform.getCropSize(pipeline_data->plate_corners,
Size(pipeline_data->config->ocrImageWidthPx, pipeline_data->config->ocrImageHeightPx));
Mat transmtx = imgTransform.getTransformationMatrix(pipeline_data->plate_corners, cropSize);
pipeline_data->crop_gray = imgTransform.crop(cropSize, transmtx);
if (this->config->debugGeneral)
displayImage(config, "quadrilateral", pipeline_data->crop_gray);
// Apply a perspective transformation to the TextLine objects
// to match the newly deskewed license plate crop
vector<TextLine> newLines;
for (uint i = 0; i < pipeline_data->textLines.size(); i++)
{
vector<Point2f> textArea = imgTransform.transformSmallPointsToBigImage(pipeline_data->textLines[i].textArea);
vector<Point2f> linePolygon = imgTransform.transformSmallPointsToBigImage(pipeline_data->textLines[i].linePolygon);
vector<Point2f> textAreaRemapped;
vector<Point2f> linePolygonRemapped;
textAreaRemapped = imgTransform.remapSmallPointstoCrop(textArea, transmtx);
linePolygonRemapped = imgTransform.remapSmallPointstoCrop(linePolygon, transmtx);
newLines.push_back(TextLine(textAreaRemapped, linePolygonRemapped));
}
pipeline_data->textLines.clear();
for (uint i = 0; i < newLines.size(); i++)
pipeline_data->textLines.push_back(newLines[i]);
if (config->debugTiming)
if (edgeFinder.confidence > 0)
{
timespec endTime;
getTime(&endTime);
cout << "deskew Time: " << diffclock(startTime, endTime) << "ms." << endl;
timespec startTime;
getTime(&startTime);
Mat originalCrop = pipeline_data->crop_gray;
Transformation imgTransform(this->pipeline_data->grayImg, pipeline_data->crop_gray, expandedRegion);
Size cropSize = imgTransform.getCropSize(pipeline_data->plate_corners,
Size(pipeline_data->config->ocrImageWidthPx, pipeline_data->config->ocrImageHeightPx));
Mat transmtx = imgTransform.getTransformationMatrix(pipeline_data->plate_corners, cropSize);
pipeline_data->crop_gray = imgTransform.crop(cropSize, transmtx);
if (this->config->debugGeneral)
displayImage(config, "quadrilateral", pipeline_data->crop_gray);
// Apply a perspective transformation to the TextLine objects
// to match the newly deskewed license plate crop
vector<TextLine> newLines;
for (uint i = 0; i < pipeline_data->textLines.size(); i++)
{
vector<Point2f> textArea = imgTransform.transformSmallPointsToBigImage(pipeline_data->textLines[i].textArea);
vector<Point2f> linePolygon = imgTransform.transformSmallPointsToBigImage(pipeline_data->textLines[i].linePolygon);
vector<Point2f> textAreaRemapped;
vector<Point2f> linePolygonRemapped;
textAreaRemapped = imgTransform.remapSmallPointstoCrop(textArea, transmtx);
linePolygonRemapped = imgTransform.remapSmallPointstoCrop(linePolygon, transmtx);
newLines.push_back(TextLine(textAreaRemapped, linePolygonRemapped));
}
pipeline_data->textLines.clear();
for (uint i = 0; i < newLines.size(); i++)
pipeline_data->textLines.push_back(newLines[i]);
if (config->debugTiming)
{
timespec endTime;
getTime(&endTime);
cout << "deskew Time: " << diffclock(startTime, endTime) << "ms." << endl;
}
charSegmenter = new CharacterSegmenter(pipeline_data);
pipeline_data->plate_area_confidence = 100;
}
charSegmenter = new CharacterSegmenter(pipeline_data);
pipeline_data->plate_area_confidence = 100;
}
}
}