mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-06 22:12:46 +08:00
Updated character segmenter to break blocks into smaller pieces.
This commit is contained in:
@@ -292,9 +292,36 @@ vector<Rect> CharacterSegmenter::getHistogramBoxes(VerticalHistogram histogram,
|
|||||||
{
|
{
|
||||||
charBoxes.push_back(allBoxes[i]);
|
charBoxes.push_back(allBoxes[i]);
|
||||||
}
|
}
|
||||||
else if (allBoxes[i].width > MAX_SEGMENT_WIDTH && allBoxes[i].height > MIN_HISTOGRAM_HEIGHT)
|
else if (allBoxes[i].width > avgCharWidth * 2 && allBoxes[i].width < MAX_SEGMENT_WIDTH * 2 && allBoxes[i].height > MIN_HISTOGRAM_HEIGHT)
|
||||||
{
|
{
|
||||||
|
// rectangle(histogram.histoImg, allBoxes[i], Scalar(255, 0, 0) );
|
||||||
|
// drawAndWait(&histogram.histoImg);
|
||||||
|
// Try to split up doubles into two good char regions, check for a break between 40% and 60%
|
||||||
|
int leftEdge = allBoxes[i].x + (int) (((float) allBoxes[i].width) * 0.4f);
|
||||||
|
int rightEdge = allBoxes[i].x + (int) (((float) allBoxes[i].width) * 0.6f);
|
||||||
|
|
||||||
|
int minX = histogram.getLocalMinimum(leftEdge, rightEdge);
|
||||||
|
int maxXChar1 = histogram.getLocalMaximum(allBoxes[i].x, minX);
|
||||||
|
int maxXChar2 = histogram.getLocalMaximum(minX, allBoxes[i].x + allBoxes[i].width);
|
||||||
|
int minHeight = histogram.getHeightAt(minX);
|
||||||
|
|
||||||
|
int maxHeightChar1 = histogram.getHeightAt(maxXChar1);
|
||||||
|
int maxHeightChar2 = histogram.getHeightAt(maxXChar2);
|
||||||
|
|
||||||
|
if (maxHeightChar1 > MIN_HISTOGRAM_HEIGHT && minHeight < (0.25 * ((float) maxHeightChar1)))
|
||||||
|
{
|
||||||
|
cout << "GOODY GOODY LEFT" << endl;
|
||||||
|
// Add a box for Char1
|
||||||
|
Point botRight = Point(minX - 1, allBoxes[i].y + allBoxes[i].height);
|
||||||
|
charBoxes.push_back(Rect(allBoxes[i].tl(), botRight) );
|
||||||
|
}
|
||||||
|
if (maxHeightChar2 > MIN_HISTOGRAM_HEIGHT && minHeight < (0.25 * ((float) maxHeightChar2)))
|
||||||
|
{
|
||||||
|
cout << "GOODY GOODY RIGHT" << endl;
|
||||||
|
// Add a box for Char2
|
||||||
|
Point topLeft = Point(minX + 1, allBoxes[i].y);
|
||||||
|
charBoxes.push_back(Rect(topLeft, allBoxes[i].br()) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -56,19 +56,60 @@ void VerticalHistogram::analyzeImage(Mat inputImage, Mat mask)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (; columnCount > 0; columnCount--)
|
|
||||||
histoImg.at<uchar>(inputImage.rows - columnCount, col) = 255;
|
|
||||||
|
|
||||||
this->colHeights.push_back(columnCount);
|
this->colHeights.push_back(columnCount);
|
||||||
|
|
||||||
if (columnCount < lowestValley)
|
if (columnCount < lowestValley)
|
||||||
lowestValley = columnCount;
|
lowestValley = columnCount;
|
||||||
if (columnCount > highestPeak)
|
if (columnCount > highestPeak)
|
||||||
highestPeak = columnCount;
|
highestPeak = columnCount;
|
||||||
|
|
||||||
|
|
||||||
|
for (; columnCount > 0; columnCount--)
|
||||||
|
histoImg.at<uchar>(inputImage.rows - columnCount, col) = 255;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int VerticalHistogram::getLocalMinimum(int leftX, int rightX)
|
||||||
|
{
|
||||||
|
int minimum = histoImg.rows + 1;
|
||||||
|
int lowestX = leftX;
|
||||||
|
|
||||||
|
for (int i = leftX; i <= rightX; i++)
|
||||||
|
{
|
||||||
|
if (colHeights[i] < minimum)
|
||||||
|
{
|
||||||
|
lowestX = i;
|
||||||
|
minimum = colHeights[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return lowestX;
|
||||||
|
}
|
||||||
|
|
||||||
|
int VerticalHistogram::getLocalMaximum(int leftX, int rightX)
|
||||||
|
{
|
||||||
|
int maximum = -1;
|
||||||
|
int highestX = leftX;
|
||||||
|
|
||||||
|
for (int i = leftX; i <= rightX; i++)
|
||||||
|
{
|
||||||
|
if (colHeights[i] > maximum)
|
||||||
|
{
|
||||||
|
highestX = i;
|
||||||
|
maximum = colHeights[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return highestX;
|
||||||
|
}
|
||||||
|
|
||||||
|
int VerticalHistogram::getHeightAt(int x)
|
||||||
|
{
|
||||||
|
return colHeights[x];
|
||||||
|
}
|
||||||
|
|
||||||
void VerticalHistogram::findValleys()
|
void VerticalHistogram::findValleys()
|
||||||
{
|
{
|
||||||
int MINIMUM_PEAK_HEIGHT = (int) (((float) highestPeak) * 0.75);
|
int MINIMUM_PEAK_HEIGHT = (int) (((float) highestPeak) * 0.75);
|
||||||
|
@@ -46,6 +46,12 @@ class VerticalHistogram
|
|||||||
|
|
||||||
Mat histoImg;
|
Mat histoImg;
|
||||||
|
|
||||||
|
// Returns the lowest X position between two points.
|
||||||
|
int getLocalMinimum(int leftX, int rightX);
|
||||||
|
// Returns the highest X position between two points.
|
||||||
|
int getLocalMaximum(int leftX, int rightX);
|
||||||
|
|
||||||
|
int getHeightAt(int x);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
vector<int> colHeights;
|
vector<int> colHeights;
|
||||||
|
Reference in New Issue
Block a user