Subversion Repositories OpenCV2-Cookbook

Rev

Rev 3 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3 Rev 5
1
/*------------------------------------------------------------------------------------------*\
1
/*------------------------------------------------------------------------------------------*\
2
   This file contains material supporting chapter 4 of the cookbook:  
2
   This file contains material supporting chapter 4 of the cookbook:  
3
   Computer Vision Programming using the OpenCV Library.
3
   Computer Vision Programming using the OpenCV Library.
4
   by Robert Laganiere, Packt Publishing, 2011.
4
   by Robert Laganiere, Packt Publishing, 2011.
5

5

6
   This program is free software; permission is hereby granted to use, copy, modify,
6
   This program is free software; permission is hereby granted to use, copy, modify,
7
   and distribute this source code, or portions thereof, for any purpose, without fee,
7
   and distribute this source code, or portions thereof, for any purpose, without fee,
8
   subject to the restriction that the copyright notice may not be removed
8
   subject to the restriction that the copyright notice may not be removed
9
   or altered from any source or altered source distribution.
9
   or altered from any source or altered source distribution.
10
   The software is released on an as-is basis and without any warranties of any kind.
10
   The software is released on an as-is basis and without any warranties of any kind.
11
   In particular, the software is not guaranteed to be fault-tolerant or free from failure.
11
   In particular, the software is not guaranteed to be fault-tolerant or free from failure.
12
   The author disclaims all warranties with regard to this software, any use,
12
   The author disclaims all warranties with regard to this software, any use,
13
   and any consequent failure, is purely the responsibility of the user.
13
   and any consequent failure, is purely the responsibility of the user.
14
 
14
 
15
   Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
15
   Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
16
\*------------------------------------------------------------------------------------------*/
16
\*------------------------------------------------------------------------------------------*/
17
17
18
#include <iostream>
18
#include <iostream>
19
using namespace std;
19
using namespace std;
20
20
21
#include <opencv2\core\core.hpp>
21
#include <opencv2/core/core.hpp>
22
#include <opencv2\highgui\highgui.hpp>
22
#include <opencv2/highgui/highgui.hpp>
23
23
24
#include "imageComparator.h"
24
#include "imageComparator.h"
25
25
26
int main()
26
int main()
27
{
27
{
28
        // Read reference image
28
        // Read reference image
29
        cv::Mat image= cv::imread("../waves.jpg");
29
        cv::Mat image= cv::imread("../waves.jpg");
30
        if (!image.data)
30
        if (!image.data)
31
                return 0;
31
                return 0;
32
32
33
        // Display image
33
        // Display image
34
        cv::namedWindow("Query Image");
34
        cv::namedWindow("Query Image");
35
        cv::imshow("Query Image",image);
35
        cv::imshow("Query Image",image);
36
36
37
        ImageComparator c;
37
        ImageComparator c;
38
        c.setReferenceImage(image);
38
        c.setReferenceImage(image);
39
39
40
        // Read an image and compare it with reference
40
        // Read an image and compare it with reference
41
        cv::Mat input= cv::imread("../dog.jpg");
41
        cv::Mat input= cv::imread("../dog.jpg");
42
        cout << "waves vs dog: " << c.compare(input) << endl;
42
        cout << "waves vs dog: " << c.compare(input) << endl;
43
43
44
        // Read an image and compare it with reference
44
        // Read an image and compare it with reference
45
        input= cv::imread("../marais.jpg");
45
        input= cv::imread("../marais.jpg");
46
        cout << "waves vs marais: " << c.compare(input) << endl;
46
        cout << "waves vs marais: " << c.compare(input) << endl;
47
47
48
        // Read an image and compare it with reference
48
        // Read an image and compare it with reference
49
        input= cv::imread("../bear.jpg");
49
        input= cv::imread("../bear.jpg");
50
        cout << "waves vs bear: " << c.compare(input) << endl;
50
        cout << "waves vs bear: " << c.compare(input) << endl;
51
51
52
        // Read an image and compare it with reference
52
        // Read an image and compare it with reference
53
        input= cv::imread("../beach.jpg");
53
        input= cv::imread("../beach.jpg");
54
        cout << "waves vs beach: " << c.compare(input) << endl;
54
        cout << "waves vs beach: " << c.compare(input) << endl;
55
55
56
        // Read an image and compare it with reference
56
        // Read an image and compare it with reference
57
        input= cv::imread("../polar.jpg");
57
        input= cv::imread("../polar.jpg");
58
        cout << "waves vs polar: " << c.compare(input) << endl;
58
        cout << "waves vs polar: " << c.compare(input) << endl;
59
59
60
        // Read an image and compare it with reference
60
        // Read an image and compare it with reference
61
        input= cv::imread("../moose.jpg");
61
        input= cv::imread("../moose.jpg");
62
        cout << "waves vs moose: " << c.compare(input) << endl;
62
        cout << "waves vs moose: " << c.compare(input) << endl;
63
63
64
        // Read an image and compare it with reference
64
        // Read an image and compare it with reference
65
        input= cv::imread("../lake.jpg");
65
        input= cv::imread("../lake.jpg");
66
        cout << "waves vs lake: " << c.compare(input) << endl;
66
        cout << "waves vs lake: " << c.compare(input) << endl;
67
67
68
        // Read an image and compare it with reference
68
        // Read an image and compare it with reference
69
        input= cv::imread("../fundy.jpg");
69
        input= cv::imread("../fundy.jpg");
70
        cout << "waves vs fundy: " << c.compare(input) << endl;
70
        cout << "waves vs fundy: " << c.compare(input) << endl;
71
71
72
        cv::waitKey();
72
        cv::waitKey();
73
        return 0;
73
        return 0;
74
}
-
 
75
74
}
-
 
75