/*
* 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 CHARACTERANALYSIS_H
#define CHARACTERANALYSIS_H
#include "opencv2/imgproc/imgproc.hpp"
#include "constants.h"
#include "utility.h"
#include "config.h"
using namespace cv;
using namespace std;
class CharacterAnalysis
{
public:
CharacterAnalysis(Mat img, Config* config);
virtual ~CharacterAnalysis();
bool hasPlateMask;
Mat plateMask;
Mat bestThreshold;
vector > bestContours;
vector bestHierarchy;
vector bestCharSegments;
int bestCharSegmentsCount;
LineSegment topLine;
LineSegment bottomLine;
vector linePolygon;
vector charArea;
LineSegment charBoxTop;
LineSegment charBoxBottom;
LineSegment charBoxLeft;
LineSegment charBoxRight;
bool thresholdsInverted;
vector thresholds;
vector > > allContours;
vector > allHierarchy;
vector > charSegments;
void analyze();
Mat getCharacterMask();
private:
Config* config;
Mat img_gray;
Mat findOuterBoxMask( );
bool isPlateInverted();
vector filter(Mat img, vector > contours, vector hierarchy);
vector filterByBoxSize(vector > contours, vector goodIndices, int minHeightPx, int maxHeightPx);
vector filterByParentContour( vector< vector< Point> > contours, vector hierarchy, vector goodIndices);
vector filterContourHoles(vector > contours, vector hierarchy, vector goodIndices);
vector filterByOuterMask(vector > contours, vector hierarchy, vector goodIndices);
vector getCharArea();
vector getBestVotedLines(Mat img, vector > contours, vector goodIndices);
//vector getCharSegmentsBetweenLines(Mat img, vector > contours, vector outerPolygon);
vector filterBetweenLines(Mat img, vector > contours, vector hierarchy, vector outerPolygon, vector goodIndices);
bool verifySize(Mat r, float minHeightPx, float maxHeightPx);
int getGoodIndicesCount(vector goodIndices);
};
#endif // CHARACTERANALYSIS_H