/* * Copyright (c) 2013 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 . */ #ifndef OPENALPR_CHARACTERSEGMENTER_H #define OPENALPR_CHARACTERSEGMENTER_H #include "opencv2/imgproc/imgproc.hpp" #include "constants.h" #include "binarize_wolf.h" #include "utility.h" #include "characterregion.h" #include "colorfilter.h" #include "verticalhistogram.h" #include "config.h" using namespace cv; using namespace std; //const float MIN_BOX_WIDTH_PX = 4; // 4 pixels const Scalar COLOR_DEBUG_EDGE(0,0,255); // Red const Scalar COLOR_DEBUG_SPECKLES(0,0,255); // Red const Scalar COLOR_DEBUG_MIN_HEIGHT(255,0,0); // Blue const Scalar COLOR_DEBUG_MIN_AREA(255,0,0); // Blue const Scalar COLOR_DEBUG_FULLBOX(255,255,0); // Blue-green const Scalar COLOR_DEBUG_COLORFILTER(255,0,255); // Magenta const Scalar COLOR_DEBUG_EMPTYFILTER(0,255,255); // Yellow class CharacterSegmenter { public: CharacterSegmenter(Mat img, bool invertedColors, Config* config); virtual ~CharacterSegmenter(); vector characters; int confidence; vector getThresholds(); private: Config* config; CharacterAnalysis* charAnalysis; LineSegment top; LineSegment bottom; vector imgDbgGeneral; vector imgDbgCleanStages; vector filter(Mat img, vector > contours, vector hierarchy); vector filterByBoxSize(vector< vector< Point> > contours, vector goodIndices, float minHeightPx, float maxHeightPx); vector filterBetweenLines(Mat img, vector > contours, vector hierarchy, vector outerPolygon, vector goodIndices); vector filterContourHoles(vector > contours, vector hierarchy, vector goodIndices); vector getBestVotedLines(Mat img, vector > contours, vector goodIndices); int getGoodIndicesCount(vector goodIndices); Mat getCharacterMask(Mat img_threshold, vector > contours, vector hierarchy, vector goodIndices); Mat getCharBoxMask(Mat img_threshold, vector charBoxes); void removeSmallContours(vector thresholds, vector > > allContours, float avgCharWidth, float avgCharHeight); Mat getVerticalHistogram(Mat img, Mat mask); vector getHistogramBoxes(VerticalHistogram histogram, float avgCharWidth, float avgCharHeight, float* score); vector getBestCharBoxes(Mat img, vector charBoxes, float avgCharWidth); vector combineCloseBoxes( vector charBoxes, float avgCharWidth); vector get1DHits(Mat img, int yOffset); void cleanCharRegions(vector thresholds, vector charRegions); void cleanBasedOnColor(vector thresholds, Mat colorMask, vector charRegions); void cleanMostlyFullBoxes(vector thresholds, const vector charRegions); vector filterMostlyEmptyBoxes(vector thresholds, const vector charRegions); void filterEdgeBoxes(vector thresholds, const vector charRegions, float avgCharWidth, float avgCharHeight); int getLongestBlobLengthBetweenLines(Mat img, int col); int isSkinnyLineInsideBox(Mat threshold, Rect box, vector > contours, vector hierarchy, float avgCharWidth, float avgCharHeight); vector getEncapsulatingLines(Mat img, vector > contours, vector goodIndices); }; #endif // OPENALPR_CHARACTERSEGMENTER_H