2
* Copyright (c) 2015 OpenALPR Technology, Inc.
3
* Open source Automated License Plate Recognition [http://www.openalpr.com]
5
* This file is part of OpenALPR.
7
* OpenALPR is free software: you can redistribute it and/or modify
8
* it under the terms of the GNU Affero General Public License
9
* version 3 as published by the Free Software Foundation
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU Affero General Public License for more details.
16
* You should have received a copy of the GNU Affero General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20
#ifndef OPENALPR_CHARACTERSEGMENTER_H
21
#define OPENALPR_CHARACTERSEGMENTER_H
23
#include "opencv2/imgproc/imgproc.hpp"
24
#include "constants.h"
25
#include "binarize_wolf.h"
27
#include "histogramvertical.h"
29
#include "textdetection/textcontours.h"
30
#include "pipeline_data.h"
36
const cv::Scalar COLOR_DEBUG_EDGE(0,0,255); // Red
37
const cv::Scalar COLOR_DEBUG_SPECKLES(0,0,255); // Red
38
const cv::Scalar COLOR_DEBUG_MIN_HEIGHT(255,0,0); // Blue
39
const cv::Scalar COLOR_DEBUG_MIN_AREA(255,0,0); // Blue
40
const cv::Scalar COLOR_DEBUG_FULLBOX(255,255,0); // Blue-green
41
const cv::Scalar COLOR_DEBUG_COLORFILTER(255,0,255); // Magenta
42
const cv::Scalar COLOR_DEBUG_EMPTYFILTER(0,255,255); // Yellow
44
class CharacterSegmenter
48
CharacterSegmenter(PipelineData* pipeline_data);
49
virtual ~CharacterSegmenter();
56
PipelineData* pipeline_data;
62
std::vector<cv::Mat> imgDbgGeneral;
63
std::vector<cv::Mat> imgDbgCleanStages;
65
cv::Mat getCharBoxMask(cv::Mat img_threshold, std::vector<cv::Rect> charBoxes);
67
void removeSmallContours(std::vector<cv::Mat> thresholds, float avgCharHeight, TextLine textLine);
69
std::vector<cv::Rect> getHistogramBoxes(HistogramVertical histogram, float avgCharWidth, float avgCharHeight, float* score);
70
std::vector<cv::Rect> getBestCharBoxes(cv::Mat img, std::vector<cv::Rect> charBoxes, float avgCharWidth);
72
int getCharGap(cv::Rect leftBox, cv::Rect rightBox);
73
std::vector<cv::Rect> combineCloseBoxes( std::vector<cv::Rect> charBoxes);
75
std::vector<cv::Rect> get1DHits(cv::Mat img, int yOffset);
77
void cleanCharRegions(std::vector<cv::Mat> thresholds, std::vector<cv::Rect> charRegions);
78
void cleanBasedOnColor(std::vector<cv::Mat> thresholds, cv::Mat colorMask, std::vector<cv::Rect> charRegions);
79
std::vector<cv::Rect> filterMostlyEmptyBoxes(std::vector<cv::Mat> thresholds, const std::vector<cv::Rect> charRegions);
80
cv::Mat filterEdgeBoxes(std::vector<cv::Mat> thresholds, const std::vector<cv::Rect> charRegions, float avgCharWidth, float avgCharHeight);
82
int getLongestBlobLengthBetweenLines(cv::Mat img, int col);
84
int isSkinnyLineInsideBox(cv::Mat threshold, cv::Rect box, std::vector<std::vector<cv::Point> > contours, std::vector<cv::Vec4i> hierarchy, float avgCharWidth, float avgCharHeight);
86
std::vector<cv::Rect> convert1DHitsToRect(std::vector<std::pair<int, int> > hits, LineSegment top, LineSegment bottom);
91
#endif // OPENALPR_CHARACTERSEGMENTER_H