diff --git a/src/openalpr/characterregion.cpp b/src/openalpr/characterregion.cpp index e698bdf..c45fea6 100644 --- a/src/openalpr/characterregion.cpp +++ b/src/openalpr/characterregion.cpp @@ -39,7 +39,7 @@ CharacterRegion::CharacterRegion(PipelineData* pipeline_data) charAnalysis->analyze(); pipeline_data->plate_inverted = charAnalysis->thresholdsInverted; - if (this->debug && charAnalysis->linePolygon.size() > 0) + if (this->debug && pipeline_data->textLines.size() > 0) { vector tempDash; for (uint z = 0; z < pipeline_data->thresholds.size(); z++) @@ -67,7 +67,7 @@ CharacterRegion::CharacterRegion(PipelineData* pipeline_data) } - if (charAnalysis->linePolygon.size() > 0) + if (pipeline_data->textLines.size() > 0) { int confidenceDrainers = 0; int charSegmentCount = charAnalysis->bestContours.getGoodIndicesCount(); diff --git a/src/openalpr/segmentation/charactersegmenter.cpp b/src/openalpr/segmentation/charactersegmenter.cpp index 1d1aefc..4797ef6 100644 --- a/src/openalpr/segmentation/charactersegmenter.cpp +++ b/src/openalpr/segmentation/charactersegmenter.cpp @@ -51,7 +51,7 @@ CharacterSegmenter::CharacterSegmenter(PipelineData* pipeline_data) displayImage(config, "CharacterSegmenter Thresholds", drawImageDashboard(pipeline_data->thresholds, CV_8U, 3)); } - if (this->config->debugCharSegmenter && charAnalysis->linePolygon.size() > 0) + if (this->config->debugCharSegmenter && pipeline_data->textLines.size() > 0) { Mat img_contours(charAnalysis->bestThreshold.size(), CV_8U); charAnalysis->bestThreshold.copyTo(img_contours); @@ -74,20 +74,21 @@ CharacterSegmenter::CharacterSegmenter(PipelineData* pipeline_data) cv::Scalar(0,255,0), // in green 1); // with a thickness of 1 - if (charAnalysis->linePolygon.size() > 0) - { - line(img_contours, charAnalysis->linePolygon[0], charAnalysis->linePolygon[1], Scalar(255, 0, 255), 1); - line(img_contours, charAnalysis->linePolygon[3], charAnalysis->linePolygon[2], Scalar(255, 0, 255), 1); - } + + line(img_contours, pipeline_data->textLines[0].linePolygon[0], pipeline_data->textLines[0].linePolygon[1], Scalar(255, 0, 255), 1); + line(img_contours, pipeline_data->textLines[0].linePolygon[3], pipeline_data->textLines[0].linePolygon[2], Scalar(255, 0, 255), 1); + Mat bordered = addLabel(img_contours, "Best Contours"); imgDbgGeneral.push_back(bordered); } - if (charAnalysis->linePolygon.size() > 0) + if (pipeline_data->textLines.size() > 0) { - this->top = LineSegment(charAnalysis->linePolygon[0].x, charAnalysis->linePolygon[0].y, charAnalysis->linePolygon[1].x, charAnalysis->linePolygon[1].y); - this->bottom = LineSegment(charAnalysis->linePolygon[3].x, charAnalysis->linePolygon[3].y, charAnalysis->linePolygon[2].x, charAnalysis->linePolygon[2].y); + this->top = LineSegment(pipeline_data->textLines[0].linePolygon[0].x, pipeline_data->textLines[0].linePolygon[0].y, + pipeline_data->textLines[0].linePolygon[1].x, pipeline_data->textLines[0].linePolygon[1].y); + this->bottom = LineSegment(pipeline_data->textLines[0].linePolygon[3].x, pipeline_data->textLines[0].linePolygon[3].y, + pipeline_data->textLines[0].linePolygon[2].x, pipeline_data->textLines[0].linePolygon[2].y); vector charWidths; vector charHeights; @@ -120,7 +121,7 @@ CharacterSegmenter::CharacterSegmenter(PipelineData* pipeline_data) { Mat histogramMask = Mat::zeros(pipeline_data->thresholds[i].size(), CV_8U); - fillConvexPoly(histogramMask, charAnalysis->linePolygon.data(), charAnalysis->linePolygon.size(), Scalar(255,255,255)); + fillConvexPoly(histogramMask, pipeline_data->textLines[0].linePolygon.data(), pipeline_data->textLines[0].linePolygon.size(), Scalar(255,255,255)); VerticalHistogram vertHistogram(pipeline_data->thresholds[i], histogramMask); diff --git a/src/openalpr/textdetection/characteranalysis.cpp b/src/openalpr/textdetection/characteranalysis.cpp index aeec953..999746f 100644 --- a/src/openalpr/textdetection/characteranalysis.cpp +++ b/src/openalpr/textdetection/characteranalysis.cpp @@ -49,6 +49,7 @@ void CharacterAnalysis::analyze() timespec startTime; getTime(&startTime); + pipeline_data->textLines.clear(); for (uint i = 0; i < pipeline_data->thresholds.size(); i++) { @@ -149,18 +150,19 @@ void CharacterAnalysis::analyze() displayImage(config, "Matching Contours", img_contours); } - this->linePolygon = getBestVotedLines(pipeline_data->crop_gray, bestContours); + vector linePolygon = getBestVotedLines(pipeline_data->crop_gray, bestContours); - if (this->linePolygon.size() > 0) + if (linePolygon.size() > 0) { - LineSegment topLine = LineSegment(this->linePolygon[0].x, this->linePolygon[0].y, this->linePolygon[1].x, this->linePolygon[1].y); - LineSegment bottomLine = LineSegment(this->linePolygon[3].x, this->linePolygon[3].y, this->linePolygon[2].x, this->linePolygon[2].y); + + LineSegment topLine = LineSegment(linePolygon[0].x, linePolygon[0].y, linePolygon[1].x, linePolygon[1].y); + LineSegment bottomLine = LineSegment(linePolygon[3].x, linePolygon[3].y, linePolygon[2].x, linePolygon[2].y); filterBetweenLines(bestThreshold, bestContours, linePolygon); - + vector textArea = getCharArea(topLine, bottomLine); - TextLine textLine(textArea, topLine, bottomLine); + TextLine textLine(textArea, linePolygon); pipeline_data->textLines.push_back(textLine); } diff --git a/src/openalpr/textdetection/characteranalysis.h b/src/openalpr/textdetection/characteranalysis.h index 3811b05..fd26ea8 100644 --- a/src/openalpr/textdetection/characteranalysis.h +++ b/src/openalpr/textdetection/characteranalysis.h @@ -39,8 +39,6 @@ class CharacterAnalysis TextContours bestContours; - std::vector linePolygon; - bool thresholdsInverted; bool isTwoLine; diff --git a/src/openalpr/textdetection/textline.cpp b/src/openalpr/textdetection/textline.cpp index d8be290..0e70d4d 100644 --- a/src/openalpr/textdetection/textline.cpp +++ b/src/openalpr/textdetection/textline.cpp @@ -20,12 +20,15 @@ #include "textline.h" -TextLine::TextLine(std::vector textArea, LineSegment topLine, LineSegment bottomLine) { +TextLine::TextLine(std::vector textArea, std::vector linePolygon) { if (textArea.size() > 0) { this->textArea = textArea; - this->topLine = topLine; - this->bottomLine = bottomLine; + this->linePolygon = linePolygon; + + this->topLine = LineSegment(linePolygon[0].x, linePolygon[0].y, linePolygon[1].x, linePolygon[1].y); + this->bottomLine = LineSegment(linePolygon[3].x, linePolygon[3].y, linePolygon[2].x, linePolygon[2].y); + this->charBoxTop = LineSegment(textArea[0].x, textArea[0].y, textArea[1].x, textArea[1].y); this->charBoxBottom = LineSegment(textArea[3].x, textArea[3].y, textArea[2].x, textArea[2].y); this->charBoxLeft = LineSegment(textArea[3].x, textArea[3].y, textArea[0].x, textArea[0].y); diff --git a/src/openalpr/textdetection/textline.h b/src/openalpr/textdetection/textline.h index ac3eeb1..cf5fc86 100644 --- a/src/openalpr/textdetection/textline.h +++ b/src/openalpr/textdetection/textline.h @@ -25,9 +25,10 @@ class TextLine { public: - TextLine(std::vector textArea, LineSegment topLine, LineSegment bottomLine); + TextLine(std::vector textArea, std::vector linePolygon); virtual ~TextLine(); + std::vector linePolygon; std::vector textArea; LineSegment topLine; LineSegment bottomLine;