mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-06 06:46:53 +08:00
Re-added despeckle filter
This commit is contained in:
@@ -44,7 +44,7 @@ CharacterSegmenter::CharacterSegmenter(PipelineData* pipeline_data)
|
|||||||
pipeline_data->clearThresholds();
|
pipeline_data->clearThresholds();
|
||||||
pipeline_data->thresholds = produceThresholds(pipeline_data->crop_gray, config);
|
pipeline_data->thresholds = produceThresholds(pipeline_data->crop_gray, config);
|
||||||
|
|
||||||
|
// TODO: Perhaps a bilateral filter would be better here.
|
||||||
medianBlur(pipeline_data->crop_gray, pipeline_data->crop_gray, 3);
|
medianBlur(pipeline_data->crop_gray, pipeline_data->crop_gray, 3);
|
||||||
|
|
||||||
if (this->config->debugCharSegmenter)
|
if (this->config->debugCharSegmenter)
|
||||||
@@ -91,20 +91,18 @@ CharacterSegmenter::CharacterSegmenter(PipelineData* pipeline_data)
|
|||||||
// imgDbgGeneral.push_back(bordered);
|
// imgDbgGeneral.push_back(bordered);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (uint lineidx = 0; lineidx < pipeline_data->textLines.size(); lineidx++)
|
for (uint lineidx = 0; lineidx < pipeline_data->textLines.size(); lineidx++)
|
||||||
{
|
{
|
||||||
this->top = pipeline_data->textLines[lineidx].topLine;
|
this->top = pipeline_data->textLines[lineidx].topLine;
|
||||||
this->bottom = pipeline_data->textLines[lineidx].bottomLine;
|
this->bottom = pipeline_data->textLines[lineidx].bottomLine;
|
||||||
|
|
||||||
|
|
||||||
float avgCharHeight = pipeline_data->textLines[lineidx].lineHeight;
|
float avgCharHeight = pipeline_data->textLines[lineidx].lineHeight;
|
||||||
float height_to_width_ratio = pipeline_data->config->charHeightMM / pipeline_data->config->charWidthMM;
|
float height_to_width_ratio = pipeline_data->config->charHeightMM / pipeline_data->config->charWidthMM;
|
||||||
float avgCharWidth = avgCharHeight / height_to_width_ratio;
|
float avgCharWidth = avgCharHeight / height_to_width_ratio;
|
||||||
//float avgCharWidth = median(charWidths.data(), charWidths.size());
|
|
||||||
|
|
||||||
//removeSmallContours(pipeline_data->thresholds, charAnalysis->allTextContours, avgCharWidth, avgCharHeight);
|
removeSmallContours(pipeline_data->thresholds, avgCharHeight, pipeline_data->textLines[lineidx]);
|
||||||
|
|
||||||
// Do the histogram analysis to figure out char regions
|
// Do the histogram analysis to figure out char regions
|
||||||
|
|
||||||
@@ -438,28 +436,38 @@ vector<Rect> CharacterSegmenter::get1DHits(Mat img, int yOffset)
|
|||||||
return hits;
|
return hits;
|
||||||
}
|
}
|
||||||
|
|
||||||
//void CharacterSegmenter::removeSmallContours(vector<Mat> thresholds, vector<TextContours> contours, float avgCharWidth, float avgCharHeight)
|
void CharacterSegmenter::removeSmallContours(vector<Mat> thresholds, float avgCharHeight, TextLine textLine)
|
||||||
//{
|
{
|
||||||
// //const float MIN_CHAR_AREA = 0.02 * avgCharWidth * avgCharHeight; // To clear out the tiny specks
|
//const float MIN_CHAR_AREA = 0.02 * avgCharWidth * avgCharHeight; // To clear out the tiny specks
|
||||||
// const float MIN_CONTOUR_HEIGHT = 0.3 * avgCharHeight;
|
const float MIN_CONTOUR_HEIGHT = 0.3 * avgCharHeight;
|
||||||
//
|
|
||||||
// for (uint i = 0; i < thresholds.size(); i++)
|
Mat textLineMask = Mat::zeros(thresholds[0].size(), CV_8U);
|
||||||
// {
|
fillConvexPoly(textLineMask, textLine.linePolygon.data(), textLine.linePolygon.size(), Scalar(255,255,255));
|
||||||
// for (uint c = 0; c < contours[i].contours.size(); c++)
|
|
||||||
// {
|
for (uint i = 0; i < thresholds.size(); i++)
|
||||||
// if (contours[i].contours[c].size() == 0)
|
{
|
||||||
// continue;
|
vector<vector<Point> > contours;
|
||||||
//
|
vector<Vec4i> hierarchy;
|
||||||
// Rect mr = boundingRect(contours[i].contours[c]);
|
Mat thresholdsCopy = Mat::zeros(thresholds[i].size(), thresholds[i].type());
|
||||||
// if (mr.height < MIN_CONTOUR_HEIGHT)
|
|
||||||
// {
|
thresholds[i].copyTo(thresholdsCopy, textLineMask);
|
||||||
// // Erase it
|
findContours(thresholdsCopy, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE);
|
||||||
// drawContours(thresholds[i], contours[i].contours, c, Scalar(0, 0, 0), -1);
|
|
||||||
// continue;
|
for (uint c = 0; c < contours.size(); c++)
|
||||||
// }
|
{
|
||||||
// }
|
if (contours[c].size() == 0)
|
||||||
// }
|
continue;
|
||||||
//}
|
|
||||||
|
Rect mr = boundingRect(contours[c]);
|
||||||
|
if (mr.height < MIN_CONTOUR_HEIGHT)
|
||||||
|
{
|
||||||
|
// Erase it
|
||||||
|
drawContours(thresholds[i], contours, c, Scalar(0, 0, 0), -1);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
vector<Rect> CharacterSegmenter::combineCloseBoxes( vector<Rect> charBoxes, float biggestCharWidth)
|
vector<Rect> CharacterSegmenter::combineCloseBoxes( vector<Rect> charBoxes, float biggestCharWidth)
|
||||||
{
|
{
|
||||||
|
@@ -64,7 +64,7 @@ class CharacterSegmenter
|
|||||||
|
|
||||||
cv::Mat getCharBoxMask(cv::Mat img_threshold, std::vector<cv::Rect> charBoxes);
|
cv::Mat getCharBoxMask(cv::Mat img_threshold, std::vector<cv::Rect> charBoxes);
|
||||||
|
|
||||||
void removeSmallContours(std::vector<cv::Mat> thresholds, std::vector<TextContours> contours, float avgCharWidth, float avgCharHeight);
|
void removeSmallContours(std::vector<cv::Mat> thresholds, float avgCharHeight, TextLine textLine);
|
||||||
|
|
||||||
std::vector<cv::Rect> getHistogramBoxes(VerticalHistogram histogram, float avgCharWidth, float avgCharHeight, float* score);
|
std::vector<cv::Rect> getHistogramBoxes(VerticalHistogram histogram, float avgCharWidth, float avgCharHeight, float* score);
|
||||||
std::vector<cv::Rect> getBestCharBoxes(cv::Mat img, std::vector<cv::Rect> charBoxes, float avgCharWidth);
|
std::vector<cv::Rect> getBestCharBoxes(cv::Mat img, std::vector<cv::Rect> charBoxes, float avgCharWidth);
|
||||||
|
Reference in New Issue
Block a user