added chamfer matcher code and sample (contributed by Antonella Cascitelli, Marco Di Stefano and Stefano Fabri)

This commit is contained in:
Vadim Pisarevsky 2010-11-30 01:34:39 +00:00
parent 84cd509639
commit 5461b9943c
5 changed files with 1443 additions and 0 deletions

View File

@ -550,6 +550,13 @@ namespace cv
CV_EXPORTS bool find4QuadCornerSubpix(const Mat& img, std::vector<Point2f>& corners, Size region_size);
CV_EXPORTS int chamerMatching( Mat& img, Mat& templ,
vector<vector<Point> >& results, vector<float>& cost,
double templScale=1, int maxMatches = 20,
double minMatchDistance = 1.0, int padX = 3,
int padY = 3, int scales = 5, double minScale = 0.6, double maxScale = 1.6,
double orientationWeight = 0.5, double truncate = 20);
}

File diff suppressed because it is too large Load Diff

48
samples/cpp/chamfer.cpp Normal file
View File

@ -0,0 +1,48 @@
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/contrib/contrib.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
if( argc != 1 && argc != 3 )
{
cout << "Usage: chamfer <image edge map> <template edge map>\n";
return 0;
}
Mat img = imread(argc == 3 ? argv[1] : "logo_in_clutter.png", 0);
Mat cimg;
cvtColor(img, cimg, CV_GRAY2BGR);
Mat tpl = imread(argc == 3 ? argv[2] : "logo.png", 0);
// if the image and the template are not edge maps but normal grayscale images,
// you might want to uncomment the lines below to produce the maps. You can also
// run Sobel instead of Canny.
// Canny(img, img, 5, 50, 3);
// Canny(tpl, tpl, 5, 50, 3);
vector<vector<Point> > results;
vector<float> costs;
int best = chamerMatching( img, tpl, results, costs );
if( best < 0 )
{
cout << "not found;\n";
return 0;
}
size_t i, n = results[best].size();
for( i = 0; i < n; i++ )
{
Point pt = results[best][i];
if( pt.inside(Rect(0, 0, cimg.cols, cimg.rows)) )
cimg.at<Vec3b>(pt) = Vec3b(0, 255, 0);
}
imshow("result", cimg);
waitKey();
return 0;
}

BIN
samples/cpp/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 939 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB