Rev 3 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3 | PointedEar | 1 | /*------------------------------------------------------------------------------------------*\ |
2 | This file contains material supporting chapter 4 of the cookbook: |
||
3 | Computer Vision Programming using the OpenCV Library. |
||
4 | by Robert Laganiere, Packt Publishing, 2011. |
||
5 | |||
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, |
||
8 | subject to the restriction that the copyright notice may not be removed |
||
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. |
||
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, |
||
13 | and any consequent failure, is purely the responsibility of the user. |
||
14 | |||
15 | Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name |
||
16 | \*------------------------------------------------------------------------------------------*/ |
||
17 | |||
18 | #if !defined ICOMPARATOR |
||
19 | #define ICOMPARATOR |
||
20 | |||
5 | PointedEar | 21 | #include <opencv2/core/core.hpp> |
22 | #include <opencv2/imgproc/imgproc.hpp> |
||
3 | PointedEar | 23 | #include "colorhistogram.h" |
24 | |||
25 | class ImageComparator { |
||
26 | |||
27 | private: |
||
28 | |||
29 | cv::Mat reference; |
||
30 | cv::Mat input; |
||
31 | cv::MatND refH; |
||
32 | cv::MatND inputH; |
||
33 | |||
34 | ColorHistogram hist; |
||
35 | int div; |
||
36 | |||
37 | public: |
||
38 | |||
39 | ImageComparator() : div(32) { |
||
40 | |||
41 | } |
||
42 | |||
43 | // Color reduction factor |
||
44 | // The comparaison will be made on images with |
||
45 | // color space reduced by this factor in each dimension |
||
46 | void setColorReduction( int factor) { |
||
47 | |||
48 | div= factor; |
||
49 | } |
||
50 | |||
51 | int getColorReduction() { |
||
52 | |||
53 | return div; |
||
54 | } |
||
55 | |||
56 | void setReferenceImage(const cv::Mat& image) { |
||
57 | |||
58 | reference= hist.colorReduce(image,div); |
||
59 | refH= hist.getHistogram(reference); |
||
60 | } |
||
61 | |||
62 | double compare(const cv::Mat& image) { |
||
63 | |||
64 | input= hist.colorReduce(image,div); |
||
65 | inputH= hist.getHistogram(input); |
||
66 | |||
67 | return cv::compareHist(refH,inputH,CV_COMP_INTERSECT); |
||
68 | } |
||
69 | }; |
||
70 | |||
71 | |||
72 | #endif |