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" #include "binarize_wolf.h"
using namespace std;
using namespace cv;
// ************************************************************* // *************************************************************
// glide a window across the image and // glide a window across the image and
// create two maps: mean and standard deviation. // create two maps: mean and standard deviation.

View File

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

View File

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

View File

@@ -25,29 +25,27 @@
#include "utility.h" #include "utility.h"
#include "config.h" #include "config.h"
using namespace cv;
using namespace std;
class CharacterAnalysis class CharacterAnalysis
{ {
public: public:
CharacterAnalysis(Mat img, Config* config); CharacterAnalysis(cv::Mat img, Config* config);
virtual ~CharacterAnalysis(); virtual ~CharacterAnalysis();
bool hasPlateMask; bool hasPlateMask;
Mat plateMask; cv::Mat plateMask;
Mat bestThreshold; cv::Mat bestThreshold;
vector<vector<Point> > bestContours; std::vector<std::vector<cv::Point> > bestContours;
vector<Vec4i> bestHierarchy; std::vector<cv::Vec4i> bestHierarchy;
vector<bool> bestCharSegments; std::vector<bool> bestCharSegments;
int bestCharSegmentsCount; int bestCharSegmentsCount;
LineSegment topLine; LineSegment topLine;
LineSegment bottomLine; LineSegment bottomLine;
vector<Point> linePolygon; std::vector<cv::Point> linePolygon;
vector<Point> charArea; std::vector<cv::Point> charArea;
LineSegment charBoxTop; LineSegment charBoxTop;
LineSegment charBoxBottom; LineSegment charBoxBottom;
@@ -56,38 +54,38 @@ class CharacterAnalysis
bool thresholdsInverted; bool thresholdsInverted;
vector<Mat> thresholds; std::vector<cv::Mat> thresholds;
vector<vector<vector<Point> > > allContours; std::vector<std::vector<std::vector<cv::Point> > > allContours;
vector<vector<Vec4i> > allHierarchy; std::vector<std::vector<cv::Vec4i> > allHierarchy;
vector<vector<bool> > charSegments; std::vector<std::vector<bool> > charSegments;
void analyze(); void analyze();
Mat getCharacterMask(); cv::Mat getCharacterMask();
private: private:
Config* config; Config* config;
Mat img_gray; cv::Mat img_gray;
Mat findOuterBoxMask( ); cv::Mat findOuterBoxMask( );
bool isPlateInverted(); 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); std::vector<bool> filterByBoxSize(std::vector<std::vector<cv::Point> > contours, std::vector<bool> goodIndices, int minHeightPx, int maxHeightPx);
vector<bool> filterByParentContour( vector< vector< Point> > contours, vector<Vec4i> hierarchy, vector<bool> goodIndices); std::vector<bool> filterByParentContour( std::vector< std::vector<cv::Point> > contours, std::vector<cv::Vec4i> hierarchy, std::vector<bool> goodIndices);
vector<bool> filterContourHoles(vector<vector<Point> > contours, vector<Vec4i> hierarchy, vector<bool> goodIndices); std::vector<bool> filterContourHoles(std::vector<std::vector<cv::Point> > contours, std::vector<cv::Vec4i> hierarchy, std::vector<bool> goodIndices);
vector<bool> filterByOuterMask(vector<vector<Point> > contours, vector<Vec4i> hierarchy, 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(); std::vector<cv::Point> getCharArea();
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<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 "characterregion.h"
//#include <apr-1.0/apr_poll.h>
#include <math.h> using namespace cv;
using namespace std;
CharacterRegion::CharacterRegion(Mat img, Config* config) CharacterRegion::CharacterRegion(Mat img, Config* config)
{ {

View File

@@ -26,25 +26,23 @@
#include "characteranalysis.h" #include "characteranalysis.h"
#include "config.h" #include "config.h"
using namespace cv;
using namespace std;
class CharacterRegion class CharacterRegion
{ {
public: public:
CharacterRegion(Mat img, Config* config); CharacterRegion(cv::Mat img, Config* config);
virtual ~CharacterRegion(); virtual ~CharacterRegion();
CharacterAnalysis *charAnalysis; CharacterAnalysis *charAnalysis;
int confidence; int confidence;
Mat getPlateMask(); cv::Mat getPlateMask();
LineSegment getTopLine(); LineSegment getTopLine();
LineSegment getBottomLine(); LineSegment getBottomLine();
//vector<Point> getLinePolygon(); //vector<Point> getLinePolygon();
vector<Point> getCharArea(); std::vector<cv::Point> getCharArea();
LineSegment getCharBoxTop(); LineSegment getCharBoxTop();
LineSegment getCharBoxBottom(); LineSegment getCharBoxBottom();
@@ -57,24 +55,24 @@ class CharacterRegion
Config* config; Config* config;
bool debug; 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); std::vector<bool> filter(cv::Mat img, std::vector<std::vector<cv::Point> > contours, std::vector<cv::Vec4i> hierarchy);
vector<bool> filterByBoxSize(Mat img, vector<vector<Point> > contours, vector<bool> goodIndices, float minHeightPx, float maxHeightPx); std::vector<bool> filterByBoxSize(cv::Mat img, std::vector<std::vector<cv::Point> > contours, std::vector<bool> goodIndices, float minHeightPx, float maxHeightPx);
vector<bool> filterByParentContour( vector< vector< Point> > contours, vector<Vec4i> hierarchy, vector<bool> goodIndices); std::vector<bool> filterByParentContour( std::vector< std::vector<cv::Point> > contours, std::vector<cv::Vec4i> hierarchy, std::vector<bool> goodIndices);
vector<bool> filterContourHoles(vector<vector<Point> > contours, vector<Vec4i> hierarchy, 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<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);
Mat getCharacterMask(Mat img, vector<vector<Point> > contours, vector<Vec4i> hierarchy, 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); std::vector<cv::Rect> wrapContours(std::vector<std::vector<cv::Point> > contours);
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);
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" #include "charactersegmenter.h"
using namespace cv;
using namespace std;
CharacterSegmenter::CharacterSegmenter(Mat img, bool invertedColors, Config* config) CharacterSegmenter::CharacterSegmenter(Mat img, bool invertedColors, Config* config)
{ {
this->config = config; this->config = config;

View File

@@ -29,30 +29,28 @@
#include "verticalhistogram.h" #include "verticalhistogram.h"
#include "config.h" #include "config.h"
using namespace cv;
using namespace std;
//const float MIN_BOX_WIDTH_PX = 4; // 4 pixels //const float MIN_BOX_WIDTH_PX = 4; // 4 pixels
const Scalar COLOR_DEBUG_EDGE(0,0,255); // Red const cv::Scalar COLOR_DEBUG_EDGE(0,0,255); // Red
const Scalar COLOR_DEBUG_SPECKLES(0,0,255); // Red const cv::Scalar COLOR_DEBUG_SPECKLES(0,0,255); // Red
const Scalar COLOR_DEBUG_MIN_HEIGHT(255,0,0); // Blue const cv::Scalar COLOR_DEBUG_MIN_HEIGHT(255,0,0); // Blue
const Scalar COLOR_DEBUG_MIN_AREA(255,0,0); // Blue const cv::Scalar COLOR_DEBUG_MIN_AREA(255,0,0); // Blue
const Scalar COLOR_DEBUG_FULLBOX(255,255,0); // Blue-green const cv::Scalar COLOR_DEBUG_FULLBOX(255,255,0); // Blue-green
const Scalar COLOR_DEBUG_COLORFILTER(255,0,255); // Magenta const cv::Scalar COLOR_DEBUG_COLORFILTER(255,0,255); // Magenta
const Scalar COLOR_DEBUG_EMPTYFILTER(0,255,255); // Yellow const cv::Scalar COLOR_DEBUG_EMPTYFILTER(0,255,255); // Yellow
class CharacterSegmenter class CharacterSegmenter
{ {
public: public:
CharacterSegmenter(Mat img, bool invertedColors, Config* config); CharacterSegmenter(cv::Mat img, bool invertedColors, Config* config);
virtual ~CharacterSegmenter(); virtual ~CharacterSegmenter();
vector<Rect> characters; std::vector<cv::Rect> characters;
int confidence; int confidence;
vector<Mat> getThresholds(); std::vector<cv::Mat> getThresholds();
private: private:
Config* config; Config* config;
@@ -62,40 +60,40 @@ class CharacterSegmenter
LineSegment top; LineSegment top;
LineSegment bottom; LineSegment bottom;
vector<Mat> imgDbgGeneral; std::vector<cv::Mat> imgDbgGeneral;
vector<Mat> imgDbgCleanStages; std::vector<cv::Mat> imgDbgCleanStages;
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, float minHeightPx, float maxHeightPx); std::vector<bool> filterByBoxSize(std::vector< std::vector<cv::Point> > contours, std::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); 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);
vector<bool> filterContourHoles(vector<vector<Point> > contours, vector<Vec4i> hierarchy, 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);
int getGoodIndicesCount(vector<bool> goodIndices); int getGoodIndicesCount(std::vector<bool> goodIndices);
Mat getCharacterMask(Mat img_threshold, vector<vector<Point> > contours, vector<Vec4i> hierarchy, vector<bool> goodIndices); cv::Mat getCharacterMask(cv::Mat img_threshold, std::vector<std::vector<cv::Point> > contours, std::vector<cv::Vec4i> hierarchy, std::vector<bool> goodIndices);
Mat getCharBoxMask(Mat img_threshold, vector<Rect> charBoxes); 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); cv::Mat getVerticalHistogram(cv::Mat img, cv::Mat mask);
vector<Rect> getHistogramBoxes(VerticalHistogram histogram, float avgCharWidth, float avgCharHeight, float* score); std::vector<cv::Rect> getHistogramBoxes(VerticalHistogram histogram, float avgCharWidth, float avgCharHeight, float* score);
vector<Rect> getBestCharBoxes(Mat img, vector<Rect> charBoxes, float avgCharWidth); std::vector<cv::Rect> getBestCharBoxes(cv::Mat img, std::vector<cv::Rect> charBoxes, float avgCharWidth);
vector<Rect> combineCloseBoxes( vector<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 cleanCharRegions(std::vector<cv::Mat> thresholds, std::vector<cv::Rect> charRegions);
void cleanBasedOnColor(vector<Mat> thresholds, Mat colorMask, vector<Rect> charRegions); void cleanBasedOnColor(std::vector<cv::Mat> thresholds, cv::Mat colorMask, std::vector<cv::Rect> charRegions);
void cleanMostlyFullBoxes(vector<Mat> thresholds, const vector<Rect> charRegions); void cleanMostlyFullBoxes(std::vector<cv::Mat> thresholds, const std::vector<cv::Rect> charRegions);
vector<Rect> filterMostlyEmptyBoxes(vector<Mat> thresholds, const vector<Rect> charRegions); std::vector<cv::Rect> filterMostlyEmptyBoxes(std::vector<cv::Mat> thresholds, const std::vector<cv::Rect> charRegions);
void filterEdgeBoxes(vector<Mat> thresholds, const vector<Rect> charRegions, float avgCharWidth, float avgCharHeight); 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 #endif // OPENALPR_CHARACTERSEGMENTER_H

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -47,7 +47,7 @@ class LineSegment
{ {
public: public:
Point p1, p2; cv::Point p1, p2;
float slope; float slope;
float length; float length;
float angle; float angle;
@@ -55,21 +55,21 @@ class LineSegment
// LineSegment(Point point1, Point point2); // LineSegment(Point point1, Point point2);
LineSegment(); LineSegment();
LineSegment(int x1, int y1, int x2, int y2); 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); void init(int x1, int y1, int x2, int y2);
bool isPointBelowLine(Point tp); bool isPointBelowLine(cv::Point tp);
float getPointAt(float x); 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); LineSegment getParallelLine(float distance);
Point midpoint(); cv::Point midpoint();
inline std::string str() inline std::string str()
{ {
@@ -82,28 +82,28 @@ class LineSegment
double median(int array[], int arraySize); 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); 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 drawX(cv::Mat img, cv::Rect rect, cv::Scalar color, int thickness);
void fillMask(Mat img, const Mat mask, Scalar color); 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 #endif // OPENALPR_UTILITY_H

View File

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

View File

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