diff --git a/src/openalpr/textdetection/characteranalysis.cpp b/src/openalpr/textdetection/characteranalysis.cpp index 703b209..d78255a 100644 --- a/src/openalpr/textdetection/characteranalysis.cpp +++ b/src/openalpr/textdetection/characteranalysis.cpp @@ -25,6 +25,8 @@ using namespace cv; using namespace std; +bool sort_text_line(TextLine i, TextLine j) { return (i.topLine.p1.y < j.topLine.p1.y); } + CharacterAnalysis::CharacterAnalysis(PipelineData* pipeline_data) { this->pipeline_data = pipeline_data; @@ -155,6 +157,9 @@ void CharacterAnalysis::analyze() filterBetweenLines(bestThreshold, bestContours, tempTextLines); + // Sort the lines from top to bottom. + std::sort(tempTextLines.begin(), tempTextLines.end(), sort_text_line); + // Now that we've filtered a few more contours, re-do the text area. for (uint i = 0; i < tempTextLines.size(); i++) { diff --git a/src/openalpr/textdetection/characteranalysis.h b/src/openalpr/textdetection/characteranalysis.h index b853072..6223cd8 100644 --- a/src/openalpr/textdetection/characteranalysis.h +++ b/src/openalpr/textdetection/characteranalysis.h @@ -20,6 +20,7 @@ #ifndef OPENALPR_CHARACTERANALYSIS_H #define OPENALPR_CHARACTERANALYSIS_H +#include #include "opencv2/imgproc/imgproc.hpp" #include "utility.h" #include "config.h"