From b32b662b19ce8901c8e440d1e27e166428b4af7a Mon Sep 17 00:00:00 2001 From: Matt Hill Date: Mon, 19 May 2014 22:14:27 -0500 Subject: [PATCH] Moved using statements out of headers and into cpp --- src/openalpr/binarize_wolf.cpp | 3 ++ src/openalpr/binarize_wolf.h | 4 +- src/openalpr/characteranalysis.cpp | 3 ++ src/openalpr/characteranalysis.h | 52 +++++++++---------- src/openalpr/characterregion.cpp | 5 +- src/openalpr/characterregion.h | 32 ++++++------ src/openalpr/charactersegmenter.cpp | 3 ++ src/openalpr/charactersegmenter.h | 70 +++++++++++++------------- src/openalpr/colorfilter.cpp | 3 ++ src/openalpr/colorfilter.h | 14 +++--- src/openalpr/config.cpp | 1 + src/openalpr/config.h | 25 +++++---- src/openalpr/featurematcher.cpp | 3 ++ src/openalpr/featurematcher.h | 28 +++++------ src/openalpr/licenseplatecandidate.cpp | 3 ++ src/openalpr/licenseplatecandidate.h | 20 ++++---- src/openalpr/platecorners.cpp | 3 ++ src/openalpr/platecorners.h | 8 ++- src/openalpr/platelines.cpp | 3 ++ src/openalpr/platelines.h | 16 +++--- src/openalpr/postprocess.cpp | 2 + src/openalpr/postprocess.h | 39 +++++++------- src/openalpr/regiondetector.cpp | 3 ++ src/openalpr/regiondetector.h | 12 ++--- src/openalpr/stateidentifier.cpp | 4 ++ src/openalpr/stateidentifier.h | 4 +- src/openalpr/utility.cpp | 3 ++ src/openalpr/utility.h | 36 ++++++------- src/openalpr/verticalhistogram.cpp | 3 ++ src/openalpr/verticalhistogram.h | 12 ++--- 30 files changed, 218 insertions(+), 199 deletions(-) diff --git a/src/openalpr/binarize_wolf.cpp b/src/openalpr/binarize_wolf.cpp index 3c3569c..38b6d85 100644 --- a/src/openalpr/binarize_wolf.cpp +++ b/src/openalpr/binarize_wolf.cpp @@ -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. diff --git a/src/openalpr/binarize_wolf.h b/src/openalpr/binarize_wolf.h index 2adf00c..1454acf 100644 --- a/src/openalpr/binarize_wolf.h +++ b/src/openalpr/binarize_wolf.h @@ -26,8 +26,6 @@ #include #include "opencv2/opencv.hpp" -using namespace std; -using namespace cv; enum NiblackVersion { @@ -44,7 +42,7 @@ enum NiblackVersion #define fget(x,y) at(y,x) #define fset(x,y,v) at(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 diff --git a/src/openalpr/characteranalysis.cpp b/src/openalpr/characteranalysis.cpp index 7e9e0af..c146504 100644 --- a/src/openalpr/characteranalysis.cpp +++ b/src/openalpr/characteranalysis.cpp @@ -19,6 +19,9 @@ #include "characteranalysis.h" +using namespace cv; +using namespace std; + CharacterAnalysis::CharacterAnalysis(Mat img, Config* config) { this->config = config; diff --git a/src/openalpr/characteranalysis.h b/src/openalpr/characteranalysis.h index c1e1dfc..588cb21 100644 --- a/src/openalpr/characteranalysis.h +++ b/src/openalpr/characteranalysis.h @@ -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 > bestContours; - vector bestHierarchy; - vector bestCharSegments; + cv::Mat bestThreshold; + std::vector > bestContours; + std::vector bestHierarchy; + std::vector bestCharSegments; int bestCharSegmentsCount; LineSegment topLine; LineSegment bottomLine; - vector linePolygon; - vector charArea; + std::vector linePolygon; + std::vector charArea; LineSegment charBoxTop; LineSegment charBoxBottom; @@ -56,38 +54,38 @@ class CharacterAnalysis bool thresholdsInverted; - vector thresholds; - vector > > allContours; - vector > allHierarchy; - vector > charSegments; + std::vector thresholds; + std::vector > > allContours; + std::vector > allHierarchy; + std::vector > 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 filter(Mat img, vector > contours, vector hierarchy); + std::vector filter(cv::Mat img, std::vector > contours, std::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); + std::vector filterByBoxSize(std::vector > contours, std::vector goodIndices, int minHeightPx, int maxHeightPx); + std::vector filterByParentContour( std::vector< std::vector > contours, std::vector hierarchy, std::vector goodIndices); + std::vector filterContourHoles(std::vector > contours, std::vector hierarchy, std::vector goodIndices); + std::vector filterByOuterMask(std::vector > contours, std::vector hierarchy, std::vector goodIndices); - vector getCharArea(); - vector getBestVotedLines(Mat img, vector > contours, vector goodIndices); + std::vector getCharArea(); + std::vector getBestVotedLines(cv::Mat img, std::vector > contours, std::vector goodIndices); //vector getCharSegmentsBetweenLines(Mat img, vector > contours, vector outerPolygon); - vector filterBetweenLines(Mat img, vector > contours, vector hierarchy, vector outerPolygon, vector goodIndices); + std::vector filterBetweenLines(cv::Mat img, std::vector > contours, std::vector hierarchy, std::vector outerPolygon, std::vector goodIndices); - bool verifySize(Mat r, float minHeightPx, float maxHeightPx); + bool verifySize(cv::Mat r, float minHeightPx, float maxHeightPx); - int getGoodIndicesCount(vector goodIndices); + int getGoodIndicesCount(std::vector goodIndices); }; diff --git a/src/openalpr/characterregion.cpp b/src/openalpr/characterregion.cpp index 55636a5..6fc4af6 100644 --- a/src/openalpr/characterregion.cpp +++ b/src/openalpr/characterregion.cpp @@ -18,8 +18,9 @@ */ #include "characterregion.h" -//#include -#include + +using namespace cv; +using namespace std; CharacterRegion::CharacterRegion(Mat img, Config* config) { diff --git a/src/openalpr/characterregion.h b/src/openalpr/characterregion.h index 902c2a9..4826bae 100644 --- a/src/openalpr/characterregion.h +++ b/src/openalpr/characterregion.h @@ -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 getLinePolygon(); - vector getCharArea(); + std::vector getCharArea(); LineSegment getCharBoxTop(); LineSegment getCharBoxBottom(); @@ -57,24 +55,24 @@ class CharacterRegion Config* config; bool debug; - Mat findOuterBoxMask(vector thresholds, vector > > allContours, vector > allHierarchy); + cv::Mat findOuterBoxMask(std::vector thresholds, std::vector > > allContours, std::vector > allHierarchy); - vector filter(Mat img, vector > contours, vector hierarchy); - vector filterByBoxSize(Mat img, vector > contours, vector goodIndices, float minHeightPx, float maxHeightPx); - vector filterByParentContour( vector< vector< Point> > contours, vector hierarchy, vector goodIndices); - vector filterContourHoles(vector > contours, vector hierarchy, vector goodIndices); + std::vector filter(cv::Mat img, std::vector > contours, std::vector hierarchy); + std::vector filterByBoxSize(cv::Mat img, std::vector > contours, std::vector goodIndices, float minHeightPx, float maxHeightPx); + std::vector filterByParentContour( std::vector< std::vector > contours, std::vector hierarchy, std::vector goodIndices); + std::vector filterContourHoles(std::vector > contours, std::vector hierarchy, std::vector goodIndices); - vector getBestVotedLines(Mat img, vector > contours, vector goodIndices); + std::vector getBestVotedLines(cv::Mat img, std::vector > contours, std::vector goodIndices); //vector getCharSegmentsBetweenLines(Mat img, vector > contours, vector outerPolygon); - vector filterBetweenLines(Mat img, vector > contours, vector hierarchy, vector outerPolygon, vector goodIndices); - Mat getCharacterMask(Mat img, vector > contours, vector hierarchy, vector goodIndices); + std::vector filterBetweenLines(cv::Mat img, std::vector > contours, std::vector hierarchy, std::vector outerPolygon, std::vector goodIndices); + cv::Mat getCharacterMask(cv::Mat img, std::vector > contours, std::vector hierarchy, std::vector goodIndices); - vector wrapContours(vector > contours); - bool verifySize(Mat r, float minHeightPx, float maxHeightPx); + std::vector wrapContours(std::vector > contours); + bool verifySize(cv::Mat r, float minHeightPx, float maxHeightPx); - int getGoodIndicesCount(vector goodIndices); + int getGoodIndicesCount(std::vector goodIndices); - bool isPlateInverted(Mat threshold, vector > contours, vector hierarchy, vector goodIndices); + bool isPlateInverted(cv::Mat threshold, std::vector > contours, std::vector hierarchy, std::vector goodIndices); }; diff --git a/src/openalpr/charactersegmenter.cpp b/src/openalpr/charactersegmenter.cpp index 1867e70..ee21178 100644 --- a/src/openalpr/charactersegmenter.cpp +++ b/src/openalpr/charactersegmenter.cpp @@ -19,6 +19,9 @@ #include "charactersegmenter.h" +using namespace cv; +using namespace std; + CharacterSegmenter::CharacterSegmenter(Mat img, bool invertedColors, Config* config) { this->config = config; diff --git a/src/openalpr/charactersegmenter.h b/src/openalpr/charactersegmenter.h index 1e9ea99..bea17b2 100644 --- a/src/openalpr/charactersegmenter.h +++ b/src/openalpr/charactersegmenter.h @@ -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 characters; + std::vector characters; int confidence; - vector getThresholds(); + std::vector getThresholds(); private: Config* config; @@ -62,40 +60,40 @@ class CharacterSegmenter LineSegment top; LineSegment bottom; - vector imgDbgGeneral; - vector imgDbgCleanStages; + std::vector imgDbgGeneral; + std::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); + std::vector filter(cv::Mat img, std::vector > contours, std::vector hierarchy); + std::vector filterByBoxSize(std::vector< std::vector > contours, std::vector goodIndices, float minHeightPx, float maxHeightPx); + std::vector filterBetweenLines(cv::Mat img, std::vector > contours, std::vector hierarchy, std::vector outerPolygon, std::vector goodIndices); + std::vector filterContourHoles(std::vector > contours, std::vector hierarchy, std::vector goodIndices); - vector getBestVotedLines(Mat img, vector > contours, vector goodIndices); - int getGoodIndicesCount(vector goodIndices); + std::vector getBestVotedLines(cv::Mat img, std::vector > contours, std::vector goodIndices); + int getGoodIndicesCount(std::vector goodIndices); - Mat getCharacterMask(Mat img_threshold, vector > contours, vector hierarchy, vector goodIndices); - Mat getCharBoxMask(Mat img_threshold, vector charBoxes); + cv::Mat getCharacterMask(cv::Mat img_threshold, std::vector > contours, std::vector hierarchy, std::vector goodIndices); + cv::Mat getCharBoxMask(cv::Mat img_threshold, std::vector charBoxes); - void removeSmallContours(vector thresholds, vector > > allContours, float avgCharWidth, float avgCharHeight); + void removeSmallContours(std::vector thresholds, std::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); + cv::Mat getVerticalHistogram(cv::Mat img, cv::Mat mask); + std::vector getHistogramBoxes(VerticalHistogram histogram, float avgCharWidth, float avgCharHeight, float* score); + std::vector getBestCharBoxes(cv::Mat img, std::vector charBoxes, float avgCharWidth); + std::vector combineCloseBoxes( std::vector charBoxes, float avgCharWidth); - vector get1DHits(Mat img, int yOffset); + std::vector get1DHits(cv::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); + void cleanCharRegions(std::vector thresholds, std::vector charRegions); + void cleanBasedOnColor(std::vector thresholds, cv::Mat colorMask, std::vector charRegions); + void cleanMostlyFullBoxes(std::vector thresholds, const std::vector charRegions); + std::vector filterMostlyEmptyBoxes(std::vector thresholds, const std::vector charRegions); + void filterEdgeBoxes(std::vector thresholds, const std::vector 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 > contours, vector hierarchy, float avgCharWidth, float avgCharHeight); + int isSkinnyLineInsideBox(cv::Mat threshold, cv::Rect box, std::vector > contours, std::vector hierarchy, float avgCharWidth, float avgCharHeight); - vector getEncapsulatingLines(Mat img, vector > contours, vector goodIndices); + std::vector getEncapsulatingLines(cv::Mat img, std::vector > contours, std::vector goodIndices); }; #endif // OPENALPR_CHARACTERSEGMENTER_H diff --git a/src/openalpr/colorfilter.cpp b/src/openalpr/colorfilter.cpp index d123bc4..58d042c 100644 --- a/src/openalpr/colorfilter.cpp +++ b/src/openalpr/colorfilter.cpp @@ -19,6 +19,9 @@ #include "colorfilter.h" +using namespace cv; +using namespace std; + ColorFilter::ColorFilter(Mat image, Mat characterMask, Config* config) { timespec startTime; diff --git a/src/openalpr/colorfilter.h b/src/openalpr/colorfilter.h index b617583..b3d26a8 100644 --- a/src/openalpr/colorfilter.h +++ b/src/openalpr/colorfilter.h @@ -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 values, float minPercentAgreement, float maxValDifference); + bool imageIsGrayscale(cv::Mat image); + int getMajorityOpinion(std::vector values, float minPercentAgreement, float maxValDifference); }; #endif // OPENALPR_COLORFILTER_H diff --git a/src/openalpr/config.cpp b/src/openalpr/config.cpp index bdce12a..3401623 100644 --- a/src/openalpr/config.cpp +++ b/src/openalpr/config.cpp @@ -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) { diff --git a/src/openalpr/config.h b/src/openalpr/config.h index 28a4d94..d09f1e0 100644 --- a/src/openalpr/config.h +++ b/src/openalpr/config.h @@ -32,7 +32,6 @@ #include /* getenv */ #include -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); }; diff --git a/src/openalpr/featurematcher.cpp b/src/openalpr/featurematcher.cpp index 268410f..287c958 100644 --- a/src/openalpr/featurematcher.cpp +++ b/src/openalpr/featurematcher.cpp @@ -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; diff --git a/src/openalpr/featurematcher.h b/src/openalpr/featurematcher.h index 1f5bf3c..2578bf1 100644 --- a/src/openalpr/featurematcher.h +++ b/src/openalpr/featurematcher.h @@ -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 debug_matches_array ); + RecognitionResult recognize( const cv::Mat& queryImg, bool drawOnImage, cv::Mat* outputImage, + bool debug_on, std::vector 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; - Ptr detector; - Ptr extractor; + cv::Ptr descriptorMatcher; + cv::Ptr detector; + cv::Ptr extractor; - vector > trainingImgKeypoints; + std::vector > trainingImgKeypoints; - void _surfStyleMatching(const Mat& queryDescriptors, vector > matchesKnn, vector& matches12); + void _surfStyleMatching(const cv::Mat& queryDescriptors, std::vector > matchesKnn, std::vector& matches12); - void crisscrossFiltering(const vector queryKeypoints, const vector inputMatches, vector &outputMatches); + void crisscrossFiltering(const std::vector queryKeypoints, const std::vector inputMatches, std::vector &outputMatches); - vector billMapping; + std::vector billMapping; - void surfStyleMatching( const Mat& queryDescriptors, vector queryKeypoints, - vector& matches12 ); + void surfStyleMatching( const cv::Mat& queryDescriptors, std::vector queryKeypoints, + std::vector& matches12 ); }; diff --git a/src/openalpr/licenseplatecandidate.cpp b/src/openalpr/licenseplatecandidate.cpp index 5cfb280..b15fad0 100644 --- a/src/openalpr/licenseplatecandidate.cpp +++ b/src/openalpr/licenseplatecandidate.cpp @@ -19,6 +19,9 @@ #include "licenseplatecandidate.h" +using namespace std; +using namespace cv; + LicensePlateCandidate::LicensePlateCandidate(Mat frame, Rect regionOfInterest, Config* config) { this->config = config; diff --git a/src/openalpr/licenseplatecandidate.h b/src/openalpr/licenseplatecandidate.h index ce64eeb..e12be32 100644 --- a/src/openalpr/licenseplatecandidate.h +++ b/src/openalpr/licenseplatecandidate.h @@ -35,8 +35,6 @@ #include "platecorners.h" #include "config.h" -using namespace std; -using namespace cv; //vector getCharacterRegions(Mat frame, vector regionsOfInterest); //vector getCharSegmentsBetweenLines(Mat img, vector > 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 points; // top-left, top-right, bottom-right, bottom-left - vector plateCorners; + std::vector 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 > charRegionContours); - vector findPlateCorners(Mat inputImage, PlateLines plateLines, CharacterRegion charRegion); // top-left, top-right, bottom-right, bottom-left + cv::Mat filterByCharacterHue(std::vector > charRegionContours); + std::vector findPlateCorners(cv::Mat inputImage, PlateLines plateLines, CharacterRegion charRegion); // top-left, top-right, bottom-right, bottom-left - vector transformPointsToOriginalImage(Mat bigImage, Mat smallImage, Rect region, vector corners); - Mat deSkewPlate(Mat inputImage, vector corners); + std::vector transformPointsToOriginalImage(cv::Mat bigImage, cv::Mat smallImage, cv::Rect region, std::vector corners); + cv::Mat deSkewPlate(cv::Mat inputImage, std::vector corners); }; diff --git a/src/openalpr/platecorners.cpp b/src/openalpr/platecorners.cpp index f6191e5..453a930 100644 --- a/src/openalpr/platecorners.cpp +++ b/src/openalpr/platecorners.cpp @@ -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; diff --git a/src/openalpr/platecorners.h b/src/openalpr/platecorners.h index 9ff7dd7..fe9d32e 100644 --- a/src/openalpr/platecorners.h +++ b/src/openalpr/platecorners.h @@ -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 findPlateCorners(); + std::vector findPlateCorners(); float confidence; private: Config* config; - Mat inputImage; + cv::Mat inputImage; float charHeight; float charAngle; diff --git a/src/openalpr/platelines.cpp b/src/openalpr/platelines.cpp index de6924b..10e13fc 100644 --- a/src/openalpr/platelines.cpp +++ b/src/openalpr/platelines.cpp @@ -19,6 +19,9 @@ #include "platelines.h" +using namespace cv; +using namespace std; + PlateLines::PlateLines(Config* config) { this->config = config; diff --git a/src/openalpr/platelines.h b/src/openalpr/platelines.h index 45fbf9d..c0fab97 100644 --- a/src/openalpr/platelines.h +++ b/src/openalpr/platelines.h @@ -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 horizontalLines; - vector verticalLines; + std::vector horizontalLines; + std::vector verticalLines; - vector winningCorners; + std::vector winningCorners; private: Config* config; bool debug; - Mat customGrayscaleConversion(Mat src); - void findLines(Mat inputImage); - vector getLines(Mat edges, float sensitivityMultiplier, bool vertical); + cv::Mat customGrayscaleConversion(cv::Mat src); + void findLines(cv::Mat inputImage); + std::vector getLines(cv::Mat edges, float sensitivityMultiplier, bool vertical); }; #endif // OPENALPR_PLATELINES_H diff --git a/src/openalpr/postprocess.cpp b/src/openalpr/postprocess.cpp index 9b23b73..18bb451 100644 --- a/src/openalpr/postprocess.cpp +++ b/src/openalpr/postprocess.cpp @@ -19,6 +19,8 @@ #include "postprocess.h" +using namespace std; + PostProcess::PostProcess(Config* config) { this->config = config; diff --git a/src/openalpr/postprocess.h b/src/openalpr/postprocess.h index d10cd43..3d8eabb 100644 --- a/src/openalpr/postprocess.h +++ b/src/openalpr/postprocess.h @@ -29,7 +29,6 @@ #include #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 skipPositions; + std::string original; + std::string regex; + std::string region; + std::vector 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 getResults(); + const std::vector getResults(); private: Config* config; //void getTopN(); - void findAllPermutations(vector prevletters, int charPos, int substitutionsLeft); + void findAllPermutations(std::vector prevletters, int charPos, int substitutionsLeft); void insertLetter(char letter, int charPosition, float score); - map > rules; + std::map > rules; float calculateMaxConfidenceScore(); - vector > letters; - vector unknownCharPositions; + std::vector > letters; + std::vector unknownCharPositions; - vector allPossibilities; + std::vector allPossibilities; // Functions used to prune the list of letters (based on topn) to improve performance - vector getMaxDepth(int topn); - int getPermutationCount(vector depth); - int getNextLeastDrop(vector depth); + std::vector getMaxDepth(int topn); + int getPermutationCount(std::vector depth); + int getNextLeastDrop(std::vector depth); }; /* diff --git a/src/openalpr/regiondetector.cpp b/src/openalpr/regiondetector.cpp index 7d2ecad..5c78070 100644 --- a/src/openalpr/regiondetector.cpp +++ b/src/openalpr/regiondetector.cpp @@ -19,6 +19,9 @@ #include "regiondetector.h" +using namespace cv; +using namespace std; + RegionDetector::RegionDetector(Config* config) { this->config = config; diff --git a/src/openalpr/regiondetector.h b/src/openalpr/regiondetector.h index c7969a8..4698738 100644 --- a/src/openalpr/regiondetector.h +++ b/src/openalpr/regiondetector.h @@ -34,8 +34,8 @@ struct PlateRegion { - Rect rect; - vector children; + cv::Rect rect; + std::vector children; }; class RegionDetector @@ -46,19 +46,19 @@ class RegionDetector virtual ~RegionDetector(); bool isLoaded(); - vector detect(Mat frame); + std::vector detect(cv::Mat frame); private: Config* config; float scale_factor; - CascadeClassifier* plate_cascade; + cv::CascadeClassifier* plate_cascade; bool loaded; - vector doCascade(Mat frame); + std::vector doCascade(cv::Mat frame); - vector aggregateRegions(vector regions); + std::vector aggregateRegions(std::vector regions); }; #endif // OPENALPR_REGIONDETECTOR_H diff --git a/src/openalpr/stateidentifier.cpp b/src/openalpr/stateidentifier.cpp index ee54326..dde5611 100644 --- a/src/openalpr/stateidentifier.cpp +++ b/src/openalpr/stateidentifier.cpp @@ -19,6 +19,10 @@ #include "stateidentifier.h" + +using namespace cv; +using namespace std; + StateIdentifier::StateIdentifier(Config* config) { this->config = config; diff --git a/src/openalpr/stateidentifier.h b/src/openalpr/stateidentifier.h index d6bd731..e0c8c0b 100644 --- a/src/openalpr/stateidentifier.h +++ b/src/openalpr/stateidentifier.h @@ -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; diff --git a/src/openalpr/utility.cpp b/src/openalpr/utility.cpp index 700f735..ce9f54a 100644 --- a/src/openalpr/utility.cpp +++ b/src/openalpr/utility.cpp @@ -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); diff --git a/src/openalpr/utility.h b/src/openalpr/utility.h index f33db31..fc10987 100644 --- a/src/openalpr/utility.h +++ b/src/openalpr/utility.h @@ -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 produceThresholds(const Mat img_gray, Config* config); +std::vector produceThresholds(const cv::Mat img_gray, Config* config); -Mat drawImageDashboard(vector images, int imageType, int numColumns); +cv::Mat drawImageDashboard(std::vector 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 diff --git a/src/openalpr/verticalhistogram.cpp b/src/openalpr/verticalhistogram.cpp index 010531a..d4adcad 100644 --- a/src/openalpr/verticalhistogram.cpp +++ b/src/openalpr/verticalhistogram.cpp @@ -19,6 +19,9 @@ #include "verticalhistogram.h" +using namespace cv; +using namespace std; + VerticalHistogram::VerticalHistogram(Mat inputImage, Mat mask) { analyzeImage(inputImage, mask); diff --git a/src/openalpr/verticalhistogram.h b/src/openalpr/verticalhistogram.h index 92c603d..3716152 100644 --- a/src/openalpr/verticalhistogram.h +++ b/src/openalpr/verticalhistogram.h @@ -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 colHeights; + std::vector colHeights; int highestPeak; int lowestValley; - vector valleys; + std::vector valleys; - void analyzeImage(Mat inputImage, Mat mask); + void analyzeImage(cv::Mat inputImage, cv::Mat mask); void findValleys(); HistogramDirection getHistogramDirection(int index);