Moved using statements out of headers and into cpp

This commit is contained in:
Matt Hill
2014-05-19 22:14:27 -05:00
parent be061ad452
commit b32b662b19
30 changed files with 218 additions and 199 deletions

View File

@@ -33,6 +33,9 @@
#include "binarize_wolf.h"
using namespace std;
using namespace cv;
// *************************************************************
// glide a window across the image and
// create two maps: mean and standard deviation.

View File

@@ -26,8 +26,6 @@
#include <iostream>
#include "opencv2/opencv.hpp"
using namespace std;
using namespace cv;
enum NiblackVersion
{
@@ -44,7 +42,7 @@ enum NiblackVersion
#define fget(x,y) at<float>(y,x)
#define fset(x,y,v) at<float>(y,x)=v;
void NiblackSauvolaWolfJolion (Mat im, Mat output, NiblackVersion version,
void NiblackSauvolaWolfJolion (cv::Mat im, cv::Mat output, NiblackVersion version,
int winx, int winy, float k);
#endif // OPENALPR_BINARIZEWOLF_H

View File

@@ -19,6 +19,9 @@
#include "characteranalysis.h"
using namespace cv;
using namespace std;
CharacterAnalysis::CharacterAnalysis(Mat img, Config* config)
{
this->config = config;

View File

@@ -25,29 +25,27 @@
#include "utility.h"
#include "config.h"
using namespace cv;
using namespace std;
class CharacterAnalysis
{
public:
CharacterAnalysis(Mat img, Config* config);
CharacterAnalysis(cv::Mat img, Config* config);
virtual ~CharacterAnalysis();
bool hasPlateMask;
Mat plateMask;
cv::Mat plateMask;
Mat bestThreshold;
vector<vector<Point> > bestContours;
vector<Vec4i> bestHierarchy;
vector<bool> bestCharSegments;
cv::Mat bestThreshold;
std::vector<std::vector<cv::Point> > bestContours;
std::vector<cv::Vec4i> bestHierarchy;
std::vector<bool> bestCharSegments;
int bestCharSegmentsCount;
LineSegment topLine;
LineSegment bottomLine;
vector<Point> linePolygon;
vector<Point> charArea;
std::vector<cv::Point> linePolygon;
std::vector<cv::Point> charArea;
LineSegment charBoxTop;
LineSegment charBoxBottom;
@@ -56,38 +54,38 @@ class CharacterAnalysis
bool thresholdsInverted;
vector<Mat> thresholds;
vector<vector<vector<Point> > > allContours;
vector<vector<Vec4i> > allHierarchy;
vector<vector<bool> > charSegments;
std::vector<cv::Mat> thresholds;
std::vector<std::vector<std::vector<cv::Point> > > allContours;
std::vector<std::vector<cv::Vec4i> > allHierarchy;
std::vector<std::vector<bool> > charSegments;
void analyze();
Mat getCharacterMask();
cv::Mat getCharacterMask();
private:
Config* config;
Mat img_gray;
cv::Mat img_gray;
Mat findOuterBoxMask( );
cv::Mat findOuterBoxMask( );
bool isPlateInverted();
vector<bool> filter(Mat img, vector<vector<Point> > contours, vector<Vec4i> hierarchy);
std::vector<bool> filter(cv::Mat img, std::vector<std::vector<cv::Point> > contours, std::vector<cv::Vec4i> hierarchy);
vector<bool> filterByBoxSize(vector<vector<Point> > contours, vector<bool> goodIndices, int minHeightPx, int maxHeightPx);
vector<bool> filterByParentContour( vector< vector< Point> > contours, vector<Vec4i> hierarchy, vector<bool> goodIndices);
vector<bool> filterContourHoles(vector<vector<Point> > contours, vector<Vec4i> hierarchy, vector<bool> goodIndices);
vector<bool> filterByOuterMask(vector<vector<Point> > contours, vector<Vec4i> hierarchy, vector<bool> goodIndices);
std::vector<bool> filterByBoxSize(std::vector<std::vector<cv::Point> > contours, std::vector<bool> goodIndices, int minHeightPx, int maxHeightPx);
std::vector<bool> filterByParentContour( std::vector< std::vector<cv::Point> > contours, std::vector<cv::Vec4i> hierarchy, std::vector<bool> goodIndices);
std::vector<bool> filterContourHoles(std::vector<std::vector<cv::Point> > contours, std::vector<cv::Vec4i> hierarchy, std::vector<bool> goodIndices);
std::vector<bool> filterByOuterMask(std::vector<std::vector<cv::Point> > contours, std::vector<cv::Vec4i> hierarchy, std::vector<bool> goodIndices);
vector<Point> getCharArea();
vector<Point> getBestVotedLines(Mat img, vector<vector<Point> > contours, vector<bool> goodIndices);
std::vector<cv::Point> getCharArea();
std::vector<cv::Point> getBestVotedLines(cv::Mat img, std::vector<std::vector<cv::Point> > contours, std::vector<bool> goodIndices);
//vector<Point> getCharSegmentsBetweenLines(Mat img, vector<vector<Point> > contours, vector<Point> outerPolygon);
vector<bool> filterBetweenLines(Mat img, vector<vector<Point> > contours, vector<Vec4i> hierarchy, vector<Point> outerPolygon, vector<bool> goodIndices);
std::vector<bool> filterBetweenLines(cv::Mat img, std::vector<std::vector<cv::Point> > contours, std::vector<cv::Vec4i> hierarchy, std::vector<cv::Point> outerPolygon, std::vector<bool> goodIndices);
bool verifySize(Mat r, float minHeightPx, float maxHeightPx);
bool verifySize(cv::Mat r, float minHeightPx, float maxHeightPx);
int getGoodIndicesCount(vector<bool> goodIndices);
int getGoodIndicesCount(std::vector<bool> goodIndices);
};

View File

@@ -18,8 +18,9 @@
*/
#include "characterregion.h"
//#include <apr-1.0/apr_poll.h>
#include <math.h>
using namespace cv;
using namespace std;
CharacterRegion::CharacterRegion(Mat img, Config* config)
{

View File

@@ -26,25 +26,23 @@
#include "characteranalysis.h"
#include "config.h"
using namespace cv;
using namespace std;
class CharacterRegion
{
public:
CharacterRegion(Mat img, Config* config);
CharacterRegion(cv::Mat img, Config* config);
virtual ~CharacterRegion();
CharacterAnalysis *charAnalysis;
int confidence;
Mat getPlateMask();
cv::Mat getPlateMask();
LineSegment getTopLine();
LineSegment getBottomLine();
//vector<Point> getLinePolygon();
vector<Point> getCharArea();
std::vector<cv::Point> getCharArea();
LineSegment getCharBoxTop();
LineSegment getCharBoxBottom();
@@ -57,24 +55,24 @@ class CharacterRegion
Config* config;
bool debug;
Mat findOuterBoxMask(vector<Mat> thresholds, vector<vector<vector<Point> > > allContours, vector<vector<Vec4i> > allHierarchy);
cv::Mat findOuterBoxMask(std::vector<cv::Mat> thresholds, std::vector<std::vector<std::vector<cv::Point> > > allContours, std::vector<std::vector<cv::Vec4i> > allHierarchy);
vector<bool> filter(Mat img, vector<vector<Point> > contours, vector<Vec4i> hierarchy);
vector<bool> filterByBoxSize(Mat img, vector<vector<Point> > contours, vector<bool> goodIndices, float minHeightPx, float maxHeightPx);
vector<bool> filterByParentContour( vector< vector< Point> > contours, vector<Vec4i> hierarchy, vector<bool> goodIndices);
vector<bool> filterContourHoles(vector<vector<Point> > contours, vector<Vec4i> hierarchy, vector<bool> goodIndices);
std::vector<bool> filter(cv::Mat img, std::vector<std::vector<cv::Point> > contours, std::vector<cv::Vec4i> hierarchy);
std::vector<bool> filterByBoxSize(cv::Mat img, std::vector<std::vector<cv::Point> > contours, std::vector<bool> goodIndices, float minHeightPx, float maxHeightPx);
std::vector<bool> filterByParentContour( std::vector< std::vector<cv::Point> > contours, std::vector<cv::Vec4i> hierarchy, std::vector<bool> goodIndices);
std::vector<bool> filterContourHoles(std::vector<std::vector<cv::Point> > contours, std::vector<cv::Vec4i> hierarchy, std::vector<bool> goodIndices);
vector<Point> getBestVotedLines(Mat img, vector<vector<Point> > contours, vector<bool> goodIndices);
std::vector<cv::Point> getBestVotedLines(cv::Mat img, std::vector<std::vector<cv::Point> > contours, std::vector<bool> goodIndices);
//vector<Point> getCharSegmentsBetweenLines(Mat img, vector<vector<Point> > contours, vector<Point> outerPolygon);
vector<bool> filterBetweenLines(Mat img, vector<vector<Point> > contours, vector<Vec4i> hierarchy, vector<Point> outerPolygon, vector<bool> goodIndices);
Mat getCharacterMask(Mat img, vector<vector<Point> > contours, vector<Vec4i> hierarchy, vector<bool> goodIndices);
std::vector<bool> filterBetweenLines(cv::Mat img, std::vector<std::vector<cv::Point> > contours, std::vector<cv::Vec4i> hierarchy, std::vector<cv::Point> outerPolygon, std::vector<bool> goodIndices);
cv::Mat getCharacterMask(cv::Mat img, std::vector<std::vector<cv::Point> > contours, std::vector<cv::Vec4i> hierarchy, std::vector<bool> goodIndices);
vector<Rect> wrapContours(vector<vector<Point> > contours);
bool verifySize(Mat r, float minHeightPx, float maxHeightPx);
std::vector<cv::Rect> wrapContours(std::vector<std::vector<cv::Point> > contours);
bool verifySize(cv::Mat r, float minHeightPx, float maxHeightPx);
int getGoodIndicesCount(vector<bool> goodIndices);
int getGoodIndicesCount(std::vector<bool> goodIndices);
bool isPlateInverted(Mat threshold, vector<vector<Point> > contours, vector<Vec4i> hierarchy, vector<bool> goodIndices);
bool isPlateInverted(cv::Mat threshold, std::vector<std::vector<cv::Point> > contours, std::vector<cv::Vec4i> hierarchy, std::vector<bool> goodIndices);
};

View File

@@ -19,6 +19,9 @@
#include "charactersegmenter.h"
using namespace cv;
using namespace std;
CharacterSegmenter::CharacterSegmenter(Mat img, bool invertedColors, Config* config)
{
this->config = config;

View File

@@ -29,30 +29,28 @@
#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
const cv::Scalar COLOR_DEBUG_EDGE(0,0,255); // Red
const cv::Scalar COLOR_DEBUG_SPECKLES(0,0,255); // Red
const cv::Scalar COLOR_DEBUG_MIN_HEIGHT(255,0,0); // Blue
const cv::Scalar COLOR_DEBUG_MIN_AREA(255,0,0); // Blue
const cv::Scalar COLOR_DEBUG_FULLBOX(255,255,0); // Blue-green
const cv::Scalar COLOR_DEBUG_COLORFILTER(255,0,255); // Magenta
const cv::Scalar COLOR_DEBUG_EMPTYFILTER(0,255,255); // Yellow
class CharacterSegmenter
{
public:
CharacterSegmenter(Mat img, bool invertedColors, Config* config);
CharacterSegmenter(cv::Mat img, bool invertedColors, Config* config);
virtual ~CharacterSegmenter();
vector<Rect> characters;
std::vector<cv::Rect> characters;
int confidence;
vector<Mat> getThresholds();
std::vector<cv::Mat> getThresholds();
private:
Config* config;
@@ -62,40 +60,40 @@ class CharacterSegmenter
LineSegment top;
LineSegment bottom;
vector<Mat> imgDbgGeneral;
vector<Mat> imgDbgCleanStages;
std::vector<cv::Mat> imgDbgGeneral;
std::vector<cv::Mat> imgDbgCleanStages;
vector<bool> filter(Mat img, vector<vector<Point> > contours, vector<Vec4i> hierarchy);
vector<bool> filterByBoxSize(vector< vector< Point> > contours, vector<bool> goodIndices, float minHeightPx, float maxHeightPx);
vector<bool> filterBetweenLines(Mat img, vector<vector<Point> > contours, vector<Vec4i> hierarchy, vector<Point> outerPolygon, vector<bool> goodIndices);
vector<bool> filterContourHoles(vector<vector<Point> > contours, vector<Vec4i> hierarchy, vector<bool> goodIndices);
std::vector<bool> filter(cv::Mat img, std::vector<std::vector<cv::Point> > contours, std::vector<cv::Vec4i> hierarchy);
std::vector<bool> filterByBoxSize(std::vector< std::vector<cv::Point> > contours, std::vector<bool> goodIndices, float minHeightPx, float maxHeightPx);
std::vector<bool> filterBetweenLines(cv::Mat img, std::vector<std::vector<cv::Point> > contours, std::vector<cv::Vec4i> hierarchy, std::vector<cv::Point> outerPolygon, std::vector<bool> goodIndices);
std::vector<bool> filterContourHoles(std::vector<std::vector<cv::Point> > contours, std::vector<cv::Vec4i> hierarchy, std::vector<bool> goodIndices);
vector<Point> getBestVotedLines(Mat img, vector<vector<Point> > contours, vector<bool> goodIndices);
int getGoodIndicesCount(vector<bool> goodIndices);
std::vector<cv::Point> getBestVotedLines(cv::Mat img, std::vector<std::vector<cv::Point> > contours, std::vector<bool> goodIndices);
int getGoodIndicesCount(std::vector<bool> goodIndices);
Mat getCharacterMask(Mat img_threshold, vector<vector<Point> > contours, vector<Vec4i> hierarchy, vector<bool> goodIndices);
Mat getCharBoxMask(Mat img_threshold, vector<Rect> charBoxes);
cv::Mat getCharacterMask(cv::Mat img_threshold, std::vector<std::vector<cv::Point> > contours, std::vector<cv::Vec4i> hierarchy, std::vector<bool> goodIndices);
cv::Mat getCharBoxMask(cv::Mat img_threshold, std::vector<cv::Rect> charBoxes);
void removeSmallContours(vector<Mat> thresholds, vector<vector<vector<Point > > > allContours, float avgCharWidth, float avgCharHeight);
void removeSmallContours(std::vector<cv::Mat> thresholds, std::vector<std::vector<std::vector<cv::Point > > > allContours, float avgCharWidth, float avgCharHeight);
Mat getVerticalHistogram(Mat img, Mat mask);
vector<Rect> getHistogramBoxes(VerticalHistogram histogram, float avgCharWidth, float avgCharHeight, float* score);
vector<Rect> getBestCharBoxes(Mat img, vector<Rect> charBoxes, float avgCharWidth);
vector<Rect> combineCloseBoxes( vector<Rect> charBoxes, float avgCharWidth);
cv::Mat getVerticalHistogram(cv::Mat img, cv::Mat mask);
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> combineCloseBoxes( std::vector<cv::Rect> charBoxes, float avgCharWidth);
vector<Rect> get1DHits(Mat img, int yOffset);
std::vector<cv::Rect> get1DHits(cv::Mat img, int yOffset);
void cleanCharRegions(vector<Mat> thresholds, vector<Rect> charRegions);
void cleanBasedOnColor(vector<Mat> thresholds, Mat colorMask, vector<Rect> charRegions);
void cleanMostlyFullBoxes(vector<Mat> thresholds, const vector<Rect> charRegions);
vector<Rect> filterMostlyEmptyBoxes(vector<Mat> thresholds, const vector<Rect> charRegions);
void filterEdgeBoxes(vector<Mat> thresholds, const vector<Rect> charRegions, float avgCharWidth, float avgCharHeight);
void cleanCharRegions(std::vector<cv::Mat> thresholds, std::vector<cv::Rect> charRegions);
void cleanBasedOnColor(std::vector<cv::Mat> thresholds, cv::Mat colorMask, std::vector<cv::Rect> charRegions);
void cleanMostlyFullBoxes(std::vector<cv::Mat> thresholds, const std::vector<cv::Rect> charRegions);
std::vector<cv::Rect> filterMostlyEmptyBoxes(std::vector<cv::Mat> thresholds, const std::vector<cv::Rect> charRegions);
void filterEdgeBoxes(std::vector<cv::Mat> thresholds, const std::vector<cv::Rect> charRegions, float avgCharWidth, float avgCharHeight);
int getLongestBlobLengthBetweenLines(Mat img, int col);
int getLongestBlobLengthBetweenLines(cv::Mat img, int col);
int isSkinnyLineInsideBox(Mat threshold, Rect box, vector<vector<Point> > contours, vector<Vec4i> hierarchy, float avgCharWidth, float avgCharHeight);
int isSkinnyLineInsideBox(cv::Mat threshold, cv::Rect box, std::vector<std::vector<cv::Point> > contours, std::vector<cv::Vec4i> hierarchy, float avgCharWidth, float avgCharHeight);
vector<Point> getEncapsulatingLines(Mat img, vector<vector<Point> > contours, vector<bool> goodIndices);
std::vector<cv::Point> getEncapsulatingLines(cv::Mat img, std::vector<std::vector<cv::Point> > contours, std::vector<bool> goodIndices);
};
#endif // OPENALPR_CHARACTERSEGMENTER_H

View File

@@ -19,6 +19,9 @@
#include "colorfilter.h"
using namespace cv;
using namespace std;
ColorFilter::ColorFilter(Mat image, Mat characterMask, Config* config)
{
timespec startTime;

View File

@@ -27,33 +27,31 @@
#include "utility.h"
#include "config.h"
using namespace cv;
using namespace std;
class ColorFilter
{
public:
ColorFilter(Mat image, Mat characterMask, Config* config);
ColorFilter(cv::Mat image, cv::Mat characterMask, Config* config);
virtual ~ColorFilter();
Mat colorMask;
cv::Mat colorMask;
private:
Config* config;
bool debug;
Mat hsv;
Mat charMask;
cv::Mat hsv;
cv::Mat charMask;
bool grayscale;
void preprocessImage();
void findCharColors();
bool imageIsGrayscale(Mat image);
int getMajorityOpinion(vector<float> values, float minPercentAgreement, float maxValDifference);
bool imageIsGrayscale(cv::Mat image);
int getMajorityOpinion(std::vector<float> values, float minPercentAgreement, float maxValDifference);
};
#endif // OPENALPR_COLORFILTER_H

View File

@@ -19,6 +19,7 @@
#include "config.h"
using namespace std;
Config::Config(const std::string country, const std::string config_file, const std::string runtime_dir)
{

View File

@@ -32,7 +32,6 @@
#include <stdlib.h> /* getenv */
#include <math.h>
using namespace std;
class Config
{
@@ -43,7 +42,7 @@ class Config
bool loaded;
string country;
std::string country;
bool opencl_enabled;
int multithreading_cores;
@@ -86,7 +85,7 @@ class Config
float segmentationMinCharHeightPercent;
float segmentationMaxCharWidthvsAverage;
string ocrLanguage;
std::string ocrLanguage;
int ocrMinFontSize;
float postProcessMinConfidence;
@@ -112,22 +111,22 @@ class Config
void debugOff();
string getKeypointsRuntimeDir();
string getCascadeRuntimeDir();
string getPostProcessRuntimeDir();
string getTessdataPrefix();
std::string getKeypointsRuntimeDir();
std::string getCascadeRuntimeDir();
std::string getPostProcessRuntimeDir();
std::string getTessdataPrefix();
private:
CSimpleIniA* ini;
string runtimeBaseDir;
std::string runtimeBaseDir;
void loadValues(string country);
void loadValues(std::string country);
int getInt(string section, string key, int defaultValue);
float getFloat(string section, string key, float defaultValue);
string getString(string section, string key, string defaultValue);
bool getBoolean(string section, string key, bool defaultValue);
int getInt(std::string section, std::string key, int defaultValue);
float getFloat(std::string section, std::string key, float defaultValue);
std::string getString(std::string section, std::string key, std::string defaultValue);
bool getBoolean(std::string section, std::string key, bool defaultValue);
};

View File

@@ -19,6 +19,9 @@
#include "featurematcher.h"
using namespace cv;
using namespace std;
//const int DEFAULT_QUERY_FEATURES = 305;
//const int DEFAULT_TRAINING_FEATURES = 305;
const float MAX_DISTANCE_TO_MATCH = 100.0f;

View File

@@ -30,13 +30,11 @@
#include "utility.h"
#include "config.h"
using namespace cv;
using namespace std;
struct RecognitionResult
{
bool haswinner;
string winner;
std::string winner;
int confidence;
} ;
@@ -47,10 +45,10 @@ class FeatureMatcher
FeatureMatcher(Config* config);
virtual ~FeatureMatcher();
RecognitionResult recognize( const Mat& queryImg, bool drawOnImage, Mat* outputImage,
bool debug_on, vector<int> debug_matches_array );
RecognitionResult recognize( const cv::Mat& queryImg, bool drawOnImage, cv::Mat* outputImage,
bool debug_on, std::vector<int> debug_matches_array );
bool loadRecognitionSet(string country);
bool loadRecognitionSet(std::string country);
bool isLoaded();
@@ -59,20 +57,20 @@ class FeatureMatcher
private:
Config* config;
Ptr<DescriptorMatcher> descriptorMatcher;
Ptr<FastFeatureDetector> detector;
Ptr<BRISK> extractor;
cv::Ptr<cv::DescriptorMatcher> descriptorMatcher;
cv::Ptr<cv::FastFeatureDetector> detector;
cv::Ptr<cv::BRISK> extractor;
vector<vector<KeyPoint> > trainingImgKeypoints;
std::vector<std::vector<cv::KeyPoint> > trainingImgKeypoints;
void _surfStyleMatching(const Mat& queryDescriptors, vector<vector<DMatch> > matchesKnn, vector<DMatch>& matches12);
void _surfStyleMatching(const cv::Mat& queryDescriptors, std::vector<std::vector<cv::DMatch> > matchesKnn, std::vector<cv::DMatch>& matches12);
void crisscrossFiltering(const vector<KeyPoint> queryKeypoints, const vector<DMatch> inputMatches, vector<DMatch> &outputMatches);
void crisscrossFiltering(const std::vector<cv::KeyPoint> queryKeypoints, const std::vector<cv::DMatch> inputMatches, std::vector<cv::DMatch> &outputMatches);
vector<string> billMapping;
std::vector<std::string> billMapping;
void surfStyleMatching( const Mat& queryDescriptors, vector<KeyPoint> queryKeypoints,
vector<DMatch>& matches12 );
void surfStyleMatching( const cv::Mat& queryDescriptors, std::vector<cv::KeyPoint> queryKeypoints,
std::vector<cv::DMatch>& matches12 );
};

View File

@@ -19,6 +19,9 @@
#include "licenseplatecandidate.h"
using namespace std;
using namespace cv;
LicensePlateCandidate::LicensePlateCandidate(Mat frame, Rect regionOfInterest, Config* config)
{
this->config = config;

View File

@@ -35,8 +35,6 @@
#include "platecorners.h"
#include "config.h"
using namespace std;
using namespace cv;
//vector<Rect> getCharacterRegions(Mat frame, vector<Rect> regionsOfInterest);
//vector<RotatedRect> getCharSegmentsBetweenLines(Mat img, vector<vector<Point> > contours, LineSegment top, LineSegment bottom);
@@ -45,30 +43,30 @@ class LicensePlateCandidate
{
public:
LicensePlateCandidate(Mat frame, Rect regionOfInterest, Config* config);
LicensePlateCandidate(cv::Mat frame, cv::Rect regionOfInterest, Config* config);
virtual ~LicensePlateCandidate();
float confidence; // 0-100
//vector<Point> points; // top-left, top-right, bottom-right, bottom-left
vector<Point2f> plateCorners;
std::vector<cv::Point2f> plateCorners;
void recognize();
Mat deskewed;
cv::Mat deskewed;
CharacterSegmenter* charSegmenter;
private:
Config* config;
Mat frame;
Rect plateRegion;
cv::Mat frame;
cv::Rect plateRegion;
Mat filterByCharacterHue(vector<vector<Point> > charRegionContours);
vector<Point> findPlateCorners(Mat inputImage, PlateLines plateLines, CharacterRegion charRegion); // top-left, top-right, bottom-right, bottom-left
cv::Mat filterByCharacterHue(std::vector<std::vector<cv::Point> > charRegionContours);
std::vector<cv::Point> findPlateCorners(cv::Mat inputImage, PlateLines plateLines, CharacterRegion charRegion); // top-left, top-right, bottom-right, bottom-left
vector<Point2f> transformPointsToOriginalImage(Mat bigImage, Mat smallImage, Rect region, vector<Point> corners);
Mat deSkewPlate(Mat inputImage, vector<Point2f> corners);
std::vector<cv::Point2f> transformPointsToOriginalImage(cv::Mat bigImage, cv::Mat smallImage, cv::Rect region, std::vector<cv::Point> corners);
cv::Mat deSkewPlate(cv::Mat inputImage, std::vector<cv::Point2f> corners);
};

View File

@@ -19,6 +19,9 @@
#include "platecorners.h"
using namespace cv;
using namespace std;
PlateCorners::PlateCorners(Mat inputImage, PlateLines* plateLines, CharacterRegion* charRegion, Config* config)
{
this->config = config;

View File

@@ -26,8 +26,6 @@
#include "utility.h"
#include "config.h"
using namespace cv;
using namespace std;
#define NO_LINE -1
@@ -46,17 +44,17 @@ class PlateCorners
{
public:
PlateCorners(Mat inputImage, PlateLines* plateLines, CharacterRegion* charRegion, Config* config);
PlateCorners(cv::Mat inputImage, PlateLines* plateLines, CharacterRegion* charRegion, Config* config);
virtual ~PlateCorners();
vector<Point> findPlateCorners();
std::vector<cv::Point> findPlateCorners();
float confidence;
private:
Config* config;
Mat inputImage;
cv::Mat inputImage;
float charHeight;
float charAngle;

View File

@@ -19,6 +19,9 @@
#include "platelines.h"
using namespace cv;
using namespace std;
PlateLines::PlateLines(Config* config)
{
this->config = config;

View File

@@ -27,8 +27,6 @@
#include "config.h"
#include "characterregion.h"
using namespace cv;
using namespace std;
class PlateLines
{
@@ -37,20 +35,20 @@ class PlateLines
PlateLines(Config* config);
virtual ~PlateLines();
void processImage(Mat img, CharacterRegion* charRegion, float sensitivity=1.0);
void processImage(cv::Mat img, CharacterRegion* charRegion, float sensitivity=1.0);
vector<LineSegment> horizontalLines;
vector<LineSegment> verticalLines;
std::vector<LineSegment> horizontalLines;
std::vector<LineSegment> verticalLines;
vector<Point> winningCorners;
std::vector<cv::Point> winningCorners;
private:
Config* config;
bool debug;
Mat customGrayscaleConversion(Mat src);
void findLines(Mat inputImage);
vector<LineSegment> getLines(Mat edges, float sensitivityMultiplier, bool vertical);
cv::Mat customGrayscaleConversion(cv::Mat src);
void findLines(cv::Mat inputImage);
std::vector<LineSegment> getLines(cv::Mat edges, float sensitivityMultiplier, bool vertical);
};
#endif // OPENALPR_PLATELINES_H

View File

@@ -19,6 +19,8 @@
#include "postprocess.h"
using namespace std;
PostProcess::PostProcess(Config* config)
{
this->config = config;

View File

@@ -29,7 +29,6 @@
#include <vector>
#include "config.h"
using namespace std;
#define SKIP_CHAR '~'
@@ -43,7 +42,7 @@ struct Letter
struct PPResult
{
string letters;
std::string letters;
float totalscore;
bool matchesTemplate;
};
@@ -54,18 +53,18 @@ bool letterCompare( const Letter &left, const Letter &right );
class RegexRule
{
public:
RegexRule(string region, string pattern);
RegexRule(std::string region, std::string pattern);
bool match(string text);
string filterSkips(string text);
bool match(std::string text);
std::string filterSkips(std::string text);
private:
int numchars;
TRexpp trexp;
string original;
string regex;
string region;
vector<int> skipPositions;
std::string original;
std::string regex;
std::string region;
std::vector<int> skipPositions;
};
class PostProcess
@@ -77,33 +76,33 @@ class PostProcess
void addLetter(char letter, int charposition, float score);
void clear();
void analyze(string templateregion, int topn);
void analyze(std::string templateregion, int topn);
string bestChars;
std::string bestChars;
bool matchesTemplate;
const vector<PPResult> getResults();
const std::vector<PPResult> getResults();
private:
Config* config;
//void getTopN();
void findAllPermutations(vector<Letter> prevletters, int charPos, int substitutionsLeft);
void findAllPermutations(std::vector<Letter> prevletters, int charPos, int substitutionsLeft);
void insertLetter(char letter, int charPosition, float score);
map<string, vector<RegexRule*> > rules;
std::map<std::string, std::vector<RegexRule*> > rules;
float calculateMaxConfidenceScore();
vector<vector<Letter> > letters;
vector<int> unknownCharPositions;
std::vector<std::vector<Letter> > letters;
std::vector<int> unknownCharPositions;
vector<PPResult> allPossibilities;
std::vector<PPResult> allPossibilities;
// Functions used to prune the list of letters (based on topn) to improve performance
vector<int> getMaxDepth(int topn);
int getPermutationCount(vector<int> depth);
int getNextLeastDrop(vector<int> depth);
std::vector<int> getMaxDepth(int topn);
int getPermutationCount(std::vector<int> depth);
int getNextLeastDrop(std::vector<int> depth);
};
/*

View File

@@ -19,6 +19,9 @@
#include "regiondetector.h"
using namespace cv;
using namespace std;
RegionDetector::RegionDetector(Config* config)
{
this->config = config;

View File

@@ -34,8 +34,8 @@
struct PlateRegion
{
Rect rect;
vector<PlateRegion> children;
cv::Rect rect;
std::vector<PlateRegion> children;
};
class RegionDetector
@@ -46,19 +46,19 @@ class RegionDetector
virtual ~RegionDetector();
bool isLoaded();
vector<PlateRegion> detect(Mat frame);
std::vector<PlateRegion> detect(cv::Mat frame);
private:
Config* config;
float scale_factor;
CascadeClassifier* plate_cascade;
cv::CascadeClassifier* plate_cascade;
bool loaded;
vector<PlateRegion> doCascade(Mat frame);
std::vector<PlateRegion> doCascade(cv::Mat frame);
vector<PlateRegion> aggregateRegions(vector<Rect> regions);
std::vector<PlateRegion> aggregateRegions(std::vector<cv::Rect> regions);
};
#endif // OPENALPR_REGIONDETECTOR_H

View File

@@ -19,6 +19,10 @@
#include "stateidentifier.h"
using namespace cv;
using namespace std;
StateIdentifier::StateIdentifier(Config* config)
{
this->config = config;

View File

@@ -33,8 +33,8 @@ class StateIdentifier
StateIdentifier(Config* config);
virtual ~StateIdentifier();
int recognize(Mat img, Rect frame, char* stateCode);
int recognize(Mat img, char* stateCode);
int recognize(cv::Mat img, cv::Rect frame, char* stateCode);
int recognize(cv::Mat img, char* stateCode);
//int confidence;

View File

@@ -19,6 +19,9 @@
#include "utility.h"
using namespace cv;
using namespace std;
Rect expandRect(Rect original, int expandXPixels, int expandYPixels, int maxX, int maxY)
{
Rect expandedRegion = Rect(original);

View File

@@ -47,7 +47,7 @@ class LineSegment
{
public:
Point p1, p2;
cv::Point p1, p2;
float slope;
float length;
float angle;
@@ -55,21 +55,21 @@ class LineSegment
// LineSegment(Point point1, Point point2);
LineSegment();
LineSegment(int x1, int y1, int x2, int y2);
LineSegment(Point p1, Point p2);
LineSegment(cv::Point p1, cv::Point p2);
void init(int x1, int y1, int x2, int y2);
bool isPointBelowLine(Point tp);
bool isPointBelowLine(cv::Point tp);
float getPointAt(float x);
Point closestPointOnSegmentTo(Point p);
cv::Point closestPointOnSegmentTo(cv::Point p);
Point intersection(LineSegment line);
cv::Point intersection(LineSegment line);
LineSegment getParallelLine(float distance);
Point midpoint();
cv::Point midpoint();
inline std::string str()
{
@@ -82,28 +82,28 @@ class LineSegment
double median(int array[], int arraySize);
vector<Mat> produceThresholds(const Mat img_gray, Config* config);
std::vector<cv::Mat> produceThresholds(const cv::Mat img_gray, Config* config);
Mat drawImageDashboard(vector<Mat> images, int imageType, int numColumns);
cv::Mat drawImageDashboard(std::vector<cv::Mat> images, int imageType, int numColumns);
void displayImage(Config* config, string windowName, cv::Mat frame);
void displayImage(Config* config, std::string windowName, cv::Mat frame);
void drawAndWait(cv::Mat* frame);
double distanceBetweenPoints(Point p1, Point p2);
double distanceBetweenPoints(cv::Point p1, cv::Point p2);
void drawRotatedRect(Mat* img, RotatedRect rect, Scalar color, int thickness);
void drawRotatedRect(cv::Mat* img, cv::RotatedRect rect, cv::Scalar color, int thickness);
void drawX(Mat img, Rect rect, Scalar color, int thickness);
void fillMask(Mat img, const Mat mask, Scalar color);
void drawX(cv::Mat img, cv::Rect rect, cv::Scalar color, int thickness);
void fillMask(cv::Mat img, const cv::Mat mask, cv::Scalar color);
float angleBetweenPoints(Point p1, Point p2);
float angleBetweenPoints(cv::Point p1, cv::Point p2);
Size getSizeMaintainingAspect(Mat inputImg, int maxWidth, int maxHeight);
cv::Size getSizeMaintainingAspect(cv::Mat inputImg, int maxWidth, int maxHeight);
Mat equalizeBrightness(Mat img);
cv::Mat equalizeBrightness(cv::Mat img);
Rect expandRect(Rect original, int expandXPixels, int expandYPixels, int maxX, int maxY);
cv::Rect expandRect(cv::Rect original, int expandXPixels, int expandYPixels, int maxX, int maxY);
Mat addLabel(Mat input, string label);
cv::Mat addLabel(cv::Mat input, std::string label);
#endif // OPENALPR_UTILITY_H

View File

@@ -19,6 +19,9 @@
#include "verticalhistogram.h"
using namespace cv;
using namespace std;
VerticalHistogram::VerticalHistogram(Mat inputImage, Mat mask)
{
analyzeImage(inputImage, mask);

View File

@@ -22,8 +22,6 @@
#include "opencv2/imgproc/imgproc.hpp"
using namespace cv;
using namespace std;
struct Valley
{
@@ -39,10 +37,10 @@ class VerticalHistogram
{
public:
VerticalHistogram(Mat inputImage, Mat mask);
VerticalHistogram(cv::Mat inputImage, cv::Mat mask);
virtual ~VerticalHistogram();
Mat histoImg;
cv::Mat histoImg;
// Returns the lowest X position between two points.
int getLocalMinimum(int leftX, int rightX);
@@ -52,12 +50,12 @@ class VerticalHistogram
int getHeightAt(int x);
private:
vector<int> colHeights;
std::vector<int> colHeights;
int highestPeak;
int lowestValley;
vector<Valley> valleys;
std::vector<Valley> valleys;
void analyzeImage(Mat inputImage, Mat mask);
void analyzeImage(cv::Mat inputImage, cv::Mat mask);
void findValleys();
HistogramDirection getHistogramDirection(int index);