cmml.cpp

A modified version of "opencv / samples / cpp /chamfer.cpp" which calls chamerMatching() a hundred times with an increasing memory usage. - Changbo Zhou, 2012-03-07 07:15 am

Download (1.9 kB)

 
1
#include "opencv2/imgproc/imgproc.hpp"
2
#include "opencv2/highgui/highgui.hpp"
3
#include "opencv2/contrib/contrib.hpp"
4
5
#include <iostream>
6
7
using namespace cv;
8
using namespace std;
9
10
void help()
11
{
12
 
13
   cout << "\nThis program demonstrates Chamfer matching -- computing a distance between an \n"
14
            "edge template and a query edge image.\n"
15
            "Usage: \n"
16
            "./chamfer <image edge map> <template edge map>,"
17
            " By default the inputs are logo_in_clutter.png logo.png\n";
18
}
19
20
const char* keys = 
21
{
22
        "{1| |logo_in_clutter.png|image edge map    }"
23
        "{2| |logo.png               |template edge map}"
24
};
25
26
int main( int argc, const char** argv )
27
{
28
29
        //help();
30
        //CommandLineParser parser(argc, argv, keys);
31
32
        string image = "black.png";
33
        string templ = "logo.png";
34
        Mat img = imread(image.c_str(), 0);
35
        Mat tpl = imread(templ.c_str(), 0);
36
37
        if (img.empty() || tpl.empty())
38
    {
39
        cout << "Could not read image file " << image << " or " << templ << "." << endl;
40
        return -1;
41
    }
42
    Mat cimg;
43
    cvtColor(img, cimg, CV_GRAY2BGR);
44
45
    // if the image and the template are not edge maps but normal grayscale images,
46
    // you might want to uncomment the lines below to produce the maps. You can also
47
    // run Sobel instead of Canny.
48
49
    // Canny(img, img, 5, 50, 3);
50
    // Canny(tpl, tpl, 5, 50, 3);
51
52
    vector<vector<Point> > results;
53
    vector<float> costs;
54
        
55
        for (int iter=0; iter<100; iter++)
56
        {
57
                int best = chamerMatching( img, tpl, results, costs );
58
                if( best < 0 )
59
                {
60
                        cout << "matching not found" << endl;
61
                        return -1;
62
                }
63
                //size_t i, n = results[best].size();
64
                //for( i = 0; i < n; i++ )
65
                //{
66
                //        Point pt = results[best][i];
67
                //        if( pt.inside(Rect(0, 0, cimg.cols, cimg.rows)) )
68
                //           cimg.at<Vec3b>(pt) = Vec3b(0, 255, 0);
69
                //}
70
        }
71
72
73
    imshow("result", cimg);
74
75
    waitKey();
76
77
    return 0;
78
}