mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-06 11:07:00 +08:00
Refactored characteranalysis. Using TextLine class to hold character info. Needed for multiline char support
This commit is contained in:
@@ -44,11 +44,13 @@ void CharacterAnalysis::analyze()
|
||||
pipeline_data->clearThresholds();
|
||||
pipeline_data->thresholds = produceThresholds(pipeline_data->crop_gray, config);
|
||||
|
||||
|
||||
|
||||
|
||||
timespec startTime;
|
||||
getTime(&startTime);
|
||||
|
||||
TextLine textLine;
|
||||
|
||||
for (uint i = 0; i < pipeline_data->thresholds.size(); i++)
|
||||
{
|
||||
TextContours tc(pipeline_data->thresholds[i]);
|
||||
@@ -148,28 +150,28 @@ void CharacterAnalysis::analyze()
|
||||
displayImage(config, "Matching Contours", img_contours);
|
||||
}
|
||||
|
||||
//charsegments = this->getPossibleCharRegions(img_threshold, allContours, allHierarchy, STARTING_MIN_HEIGHT + (bestFitIndex * HEIGHT_STEP), STARTING_MAX_HEIGHT + (bestFitIndex * HEIGHT_STEP));
|
||||
|
||||
this->linePolygon = getBestVotedLines(pipeline_data->crop_gray, bestContours);
|
||||
|
||||
if (this->linePolygon.size() > 0)
|
||||
{
|
||||
this->topLine = LineSegment(this->linePolygon[0].x, this->linePolygon[0].y, this->linePolygon[1].x, this->linePolygon[1].y);
|
||||
this->bottomLine = LineSegment(this->linePolygon[3].x, this->linePolygon[3].y, this->linePolygon[2].x, this->linePolygon[2].y);
|
||||
//this->charArea = getCharSegmentsBetweenLines(bestThreshold, bestContours, this->linePolygon);
|
||||
textLine.topLine = LineSegment(this->linePolygon[0].x, this->linePolygon[0].y, this->linePolygon[1].x, this->linePolygon[1].y);
|
||||
textLine.bottomLine = LineSegment(this->linePolygon[3].x, this->linePolygon[3].y, this->linePolygon[2].x, this->linePolygon[2].y);
|
||||
|
||||
filterBetweenLines(bestThreshold, bestContours, linePolygon);
|
||||
|
||||
this->charArea = getCharArea();
|
||||
textLine.textArea = getCharArea(textLine.topLine, textLine.bottomLine);
|
||||
|
||||
if (this->charArea.size() > 0)
|
||||
if (textLine.textArea.size() > 0)
|
||||
{
|
||||
this->charBoxTop = LineSegment(this->charArea[0].x, this->charArea[0].y, this->charArea[1].x, this->charArea[1].y);
|
||||
this->charBoxBottom = LineSegment(this->charArea[3].x, this->charArea[3].y, this->charArea[2].x, this->charArea[2].y);
|
||||
this->charBoxLeft = LineSegment(this->charArea[3].x, this->charArea[3].y, this->charArea[0].x, this->charArea[0].y);
|
||||
this->charBoxRight = LineSegment(this->charArea[2].x, this->charArea[2].y, this->charArea[1].x, this->charArea[1].y);
|
||||
textLine.charBoxTop = LineSegment(textLine.textArea[0].x, textLine.textArea[0].y, textLine.textArea[1].x, textLine.textArea[1].y);
|
||||
textLine.charBoxBottom = LineSegment(textLine.textArea[3].x, textLine.textArea[3].y, textLine.textArea[2].x, textLine.textArea[2].y);
|
||||
textLine.charBoxLeft = LineSegment(textLine.textArea[3].x, textLine.textArea[3].y, textLine.textArea[0].x, textLine.textArea[0].y);
|
||||
textLine.charBoxRight = LineSegment(textLine.textArea[2].x, textLine.textArea[2].y, textLine.textArea[1].x, textLine.textArea[1].y);
|
||||
}
|
||||
}
|
||||
|
||||
pipeline_data->textLines.push_back(textLine);
|
||||
|
||||
this->thresholdsInverted = isPlateInverted();
|
||||
}
|
||||
|
||||
@@ -733,7 +735,7 @@ bool CharacterAnalysis::verifySize(Mat r, float minHeightPx, float maxHeightPx)
|
||||
return false;
|
||||
}
|
||||
|
||||
vector<Point> CharacterAnalysis::getCharArea()
|
||||
vector<Point> CharacterAnalysis::getCharArea(LineSegment topLine, LineSegment bottomLine)
|
||||
{
|
||||
const int MAX = 100000;
|
||||
const int MIN= -1;
|
||||
|
@@ -43,15 +43,10 @@ class CharacterAnalysis
|
||||
//std::vector<bool> bestCharSegments;
|
||||
//int bestCharSegmentsCount;
|
||||
|
||||
LineSegment topLine;
|
||||
LineSegment bottomLine;
|
||||
std::vector<cv::Point> linePolygon;
|
||||
std::vector<cv::Point> charArea;
|
||||
|
||||
LineSegment charBoxTop;
|
||||
LineSegment charBoxBottom;
|
||||
LineSegment charBoxLeft;
|
||||
LineSegment charBoxRight;
|
||||
std::vector<cv::Point> linePolygon;
|
||||
|
||||
|
||||
|
||||
bool thresholdsInverted;
|
||||
bool isTwoLine;
|
||||
@@ -79,7 +74,7 @@ class CharacterAnalysis
|
||||
void filterContourHoles(TextContours& textContours);
|
||||
void filterByOuterMask(TextContours& textContours);
|
||||
|
||||
std::vector<cv::Point> getCharArea();
|
||||
std::vector<cv::Point> getCharArea(LineSegment topLine, LineSegment bottomLine);
|
||||
std::vector<cv::Point> getBestVotedLines(cv::Mat img, TextContours textContours);
|
||||
void filterBetweenLines(cv::Mat img, TextContours& textContours, std::vector<cv::Point> outerPolygon );
|
||||
|
||||
|
@@ -1,9 +1,21 @@
|
||||
/*
|
||||
* File: textcontours.cpp
|
||||
* Author: mhill
|
||||
*
|
||||
* Created on October 9, 2014, 7:40 PM
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2014 New Designs Unlimited, LLC
|
||||
* Opensource Automated License Plate Recognition [http://www.openalpr.com]
|
||||
*
|
||||
* This file is part of OpenAlpr.
|
||||
*
|
||||
* OpenAlpr is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License
|
||||
* version 3 as published by the Free Software Foundation
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "textcontours.h"
|
||||
|
||||
|
@@ -1,9 +1,21 @@
|
||||
/*
|
||||
* File: textcontours.h
|
||||
* Author: mhill
|
||||
/*
|
||||
* Copyright (c) 2014 New Designs Unlimited, LLC
|
||||
* Opensource Automated License Plate Recognition [http://www.openalpr.com]
|
||||
*
|
||||
* Created on October 9, 2014, 7:40 PM
|
||||
*/
|
||||
* This file is part of OpenAlpr.
|
||||
*
|
||||
* OpenAlpr is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License
|
||||
* version 3 as published by the Free Software Foundation
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TEXTCONTOURS_H
|
||||
#define TEXTCONTOURS_H
|
||||
|
28
src/openalpr/textdetection/textline.cpp
Normal file
28
src/openalpr/textdetection/textline.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) 2014 New Designs Unlimited, LLC
|
||||
* Opensource Automated License Plate Recognition [http://www.openalpr.com]
|
||||
*
|
||||
* This file is part of OpenAlpr.
|
||||
*
|
||||
* OpenAlpr is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License
|
||||
* version 3 as published by the Free Software Foundation
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "textline.h"
|
||||
|
||||
TextLine::TextLine() {
|
||||
}
|
||||
|
||||
|
||||
TextLine::~TextLine() {
|
||||
}
|
45
src/openalpr/textdetection/textline.h
Normal file
45
src/openalpr/textdetection/textline.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2014 New Designs Unlimited, LLC
|
||||
* Opensource Automated License Plate Recognition [http://www.openalpr.com]
|
||||
*
|
||||
* This file is part of OpenAlpr.
|
||||
*
|
||||
* OpenAlpr is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License
|
||||
* version 3 as published by the Free Software Foundation
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef OPENALPR_TEXTLINE_H
|
||||
#define OPENALPR_TEXTLINE_H
|
||||
|
||||
#include "utility.h"
|
||||
|
||||
class TextLine {
|
||||
public:
|
||||
TextLine();
|
||||
virtual ~TextLine();
|
||||
|
||||
std::vector<cv::Point> textArea;
|
||||
LineSegment topLine;
|
||||
LineSegment bottomLine;
|
||||
|
||||
LineSegment charBoxTop;
|
||||
LineSegment charBoxBottom;
|
||||
LineSegment charBoxLeft;
|
||||
LineSegment charBoxRight;
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif /* OPENALPR_TEXTLINE_H */
|
||||
|
Reference in New Issue
Block a user