Moved 1-dimensional histogram hit to histogram class

This commit is contained in:
Matt Hill
2015-09-20 21:13:39 -04:00
parent 354d6110f8
commit b3afab7c60
2 changed files with 19 additions and 32 deletions

View File

@@ -214,7 +214,7 @@ namespace alpr
int pxLeniency = 2;
vector<Rect> charBoxes;
vector<Rect> allBoxes = get1DHits(histogram.histoImg, pxLeniency);
vector<Rect> allBoxes = convert1DHitsToRect(histogram.get1DHits(pxLeniency), top, bottom);
for (unsigned int i = 0; i < allBoxes.size(); i++)
{
@@ -294,7 +294,9 @@ namespace alpr
for (int row = 0; row < histoImg.rows; row++)
{
vector<Rect> validBoxes;
vector<Rect> allBoxes = get1DHits(histoImg, row);
int pxLeniency = 2;
vector<Rect> allBoxes = convert1DHitsToRect(histogram.get1DHits(pxLeniency), top, bottom);
if (this->config->debugCharSegmenter)
cout << "All Boxes size " << allBoxes.size() << endl;
@@ -373,36 +375,6 @@ namespace alpr
return bestBoxes;
}
vector<Rect> CharacterSegmenter::get1DHits(Mat img, int yOffset)
{
vector<Rect> hits;
bool onSegment = false;
int curSegmentLength = 0;
for (int col = 0; col < img.cols; col++)
{
bool isOn = img.at<uchar>(img.rows - 1 - yOffset, col);
if (isOn)
{
// We're on a segment. Increment the length
onSegment = true;
curSegmentLength++;
}
if (onSegment && (isOn == false || (col == img.cols - 1)))
{
// A segment just ended or we're at the very end of the row and we're on a segment
Point topLeft = Point(col - curSegmentLength, top.getPointAt(col - curSegmentLength) - 1);
Point botRight = Point(col, bottom.getPointAt(col) + 1);
hits.push_back(Rect(topLeft, botRight));
onSegment = false;
curSegmentLength = 0;
}
}
return hits;
}
void CharacterSegmenter::removeSmallContours(vector<Mat> thresholds, float avgCharHeight, TextLine textLine)
{
@@ -1020,5 +992,19 @@ namespace alpr
return mask;
}
std::vector<cv::Rect> CharacterSegmenter::convert1DHitsToRect(vector<pair<int, int> > hits, LineSegment top, LineSegment bottom) {
vector<Rect> boxes;
for (unsigned int i = 0; i < hits.size(); i++)
{
Point topLeft = Point(hits[i].first, top.getPointAt(hits[i].first) - 1);
Point botRight = Point(hits[i].second, bottom.getPointAt(hits[i].second) + 1);
boxes.push_back(Rect(topLeft, botRight));
}
return boxes;
}
}

View File

@@ -81,6 +81,7 @@ namespace alpr
int isSkinnyLineInsideBox(cv::Mat threshold, cv::Rect box, std::vector<std::vector<cv::Point> > contours, std::vector<cv::Vec4i> hierarchy, float avgCharWidth, float avgCharHeight);
std::vector<cv::Rect> convert1DHitsToRect(std::vector<std::pair<int, int> > hits, LineSegment top, LineSegment bottom);
};
}