Moved featurematcher into separate library

This commit is contained in:
Matt Hill
2015-08-09 19:19:59 -04:00
parent ec27b51c2b
commit 5101e2b9b4
2 changed files with 24 additions and 22 deletions

View File

@@ -29,10 +29,8 @@ namespace alpr
//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;
FeatureMatcher::FeatureMatcher(Config* config) FeatureMatcher::FeatureMatcher()
{ {
this->config = config;
//this->descriptorMatcher = DescriptorMatcher::create( "BruteForce-HammingLUT" ); //this->descriptorMatcher = DescriptorMatcher::create( "BruteForce-HammingLUT" );
this->descriptorMatcher = new BFMatcher(NORM_HAMMING, false); this->descriptorMatcher = new BFMatcher(NORM_HAMMING, false);
@@ -152,8 +150,8 @@ namespace alpr
// We assume that license plates won't be upside-down or backwards. So expect lines to be closely parallel // We assume that license plates won't be upside-down or backwards. So expect lines to be closely parallel
void FeatureMatcher::crisscrossFiltering(const vector<KeyPoint> queryKeypoints, const vector<DMatch> inputMatches, vector<DMatch> &outputMatches) void FeatureMatcher::crisscrossFiltering(const vector<KeyPoint> queryKeypoints, const vector<DMatch> inputMatches, vector<DMatch> &outputMatches)
{ {
Rect crissCrossAreaVertical(0, 0, config->stateIdImageWidthPx, config->stateIdimageHeightPx * 2); Rect crissCrossAreaVertical(0, 0, w, h * 2);
Rect crissCrossAreaHorizontal(0, 0, config->stateIdImageWidthPx * 2, config->stateIdimageHeightPx); Rect crissCrossAreaHorizontal(0, 0, w * 2, h);
for (unsigned int i = 0; i < billMapping.size(); i++) for (unsigned int i = 0; i < billMapping.size(); i++)
{ {
@@ -175,8 +173,8 @@ namespace alpr
KeyPoint tkp = trainingImgKeypoints[i][matchesForOnePlate[j].trainIdx]; KeyPoint tkp = trainingImgKeypoints[i][matchesForOnePlate[j].trainIdx];
KeyPoint qkp = queryKeypoints[matchesForOnePlate[j].queryIdx]; KeyPoint qkp = queryKeypoints[matchesForOnePlate[j].queryIdx];
vlines.push_back(LineSegment(tkp.pt.x, tkp.pt.y + config->stateIdimageHeightPx, qkp.pt.x, qkp.pt.y)); vlines.push_back(LineSegment(tkp.pt.x, tkp.pt.y + h, qkp.pt.x, qkp.pt.y));
hlines.push_back(LineSegment(tkp.pt.x, tkp.pt.y, qkp.pt.x + config->stateIdImageWidthPx, qkp.pt.y)); hlines.push_back(LineSegment(tkp.pt.x, tkp.pt.y, qkp.pt.x + w, qkp.pt.y));
matchIdx.push_back(j); matchIdx.push_back(j);
} }
@@ -215,8 +213,8 @@ namespace alpr
if (mostIntersectionsIndex >= 0) if (mostIntersectionsIndex >= 0)
{ {
if (this->config->debugStateId) // if (this->config->debugStateId)
cout << "Filtered intersection! " << billMapping[i] << endl; // cout << "Filtered intersection! " << billMapping[i] << endl;
vlines.erase(vlines.begin() + mostIntersectionsIndex); vlines.erase(vlines.begin() + mostIntersectionsIndex);
hlines.erase(hlines.begin() + mostIntersectionsIndex); hlines.erase(hlines.begin() + mostIntersectionsIndex);
matchIdx.erase(matchIdx.begin() + mostIntersectionsIndex); matchIdx.erase(matchIdx.begin() + mostIntersectionsIndex);
@@ -232,10 +230,10 @@ namespace alpr
} }
// Returns true if successful, false otherwise // Returns true if successful, false otherwise
bool FeatureMatcher::loadRecognitionSet(string country) bool FeatureMatcher::loadRecognitionSet(string directory, string country)
{ {
std::ostringstream out; std::ostringstream out;
out << config->getKeypointsRuntimeDir() << "/" << country << "/"; out << directory << "/keypoints/" << country << "/";
string country_dir = out.str(); string country_dir = out.str();
if (DirectoryExists(country_dir.c_str())) if (DirectoryExists(country_dir.c_str()))
@@ -253,7 +251,6 @@ namespace alpr
// convert to gray and resize to the size of the templates // convert to gray and resize to the size of the templates
cvtColor(img, img, CV_BGR2GRAY); cvtColor(img, img, CV_BGR2GRAY);
resize(img, img, getSizeMaintainingAspect(img, config->stateIdImageWidthPx, config->stateIdimageHeightPx));
if( img.empty() ) if( img.empty() )
{ {
@@ -290,6 +287,9 @@ namespace alpr
{ {
RecognitionResult result; RecognitionResult result;
this->w = queryImg.cols;
this->h = queryImg.rows;
result.haswinner = false; result.haswinner = false;
result.confidence = 0; result.confidence = 0;
@@ -381,13 +381,13 @@ namespace alpr
} }
} }
if (this->config->debugStateId) // if (this->config->debugStateId)
{ // {
for (unsigned int i = 0; i < billMapping.size(); i++) // for (unsigned int i = 0; i < billMapping.size(); i++)
{ // {
cout << billMapping[i] << " : " << bill_match_counts[i] << endl; // cout << billMapping[i] << " : " << bill_match_counts[i] << endl;
} // }
} // }
return result; return result;
} }

View File

@@ -44,20 +44,19 @@ namespace alpr
{ {
public: public:
FeatureMatcher(Config* config); FeatureMatcher();
virtual ~FeatureMatcher(); virtual ~FeatureMatcher();
RecognitionResult recognize( const cv::Mat& queryImg, bool drawOnImage, cv::Mat* outputImage, RecognitionResult recognize( const cv::Mat& queryImg, bool drawOnImage, cv::Mat* outputImage,
bool debug_on, std::vector<int> debug_matches_array ); bool debug_on, std::vector<int> debug_matches_array );
bool loadRecognitionSet(std::string country); bool loadRecognitionSet(std::string runtime_dir, std::string country);
bool isLoaded(); bool isLoaded();
int numTrainingElements(); int numTrainingElements();
private: private:
Config* config;
cv::Ptr<cv::DescriptorMatcher> descriptorMatcher; cv::Ptr<cv::DescriptorMatcher> descriptorMatcher;
cv::Ptr<cv::FastFeatureDetector> detector; cv::Ptr<cv::FastFeatureDetector> detector;
@@ -74,6 +73,9 @@ namespace alpr
void surfStyleMatching( const cv::Mat& queryDescriptors, std::vector<cv::KeyPoint> queryKeypoints, void surfStyleMatching( const cv::Mat& queryDescriptors, std::vector<cv::KeyPoint> queryKeypoints,
std::vector<cv::DMatch>& matches12 ); std::vector<cv::DMatch>& matches12 );
int w;
int h;
}; };
} }