diff options
Diffstat (limited to 'cvtest/src/imageComparator.h')
| -rwxr-xr-x | cvtest/src/imageComparator.h | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/cvtest/src/imageComparator.h b/cvtest/src/imageComparator.h new file mode 100755 index 0000000..c1904c6 --- /dev/null +++ b/cvtest/src/imageComparator.h @@ -0,0 +1,71 @@ +/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 4 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#if !defined ICOMPARATOR
+#define ICOMPARATOR
+
+#include <opencv2/opencv.hpp>
+#include "colorhistogram.h"
+
+class ImageComparator {
+
+ private:
+
+ cv::Mat reference;
+ cv::Mat input;
+ cv::MatND refH;
+ cv::MatND inputH;
+
+ ColorHistogram hist;
+ int div;
+
+ public:
+
+ ImageComparator() : div(32) {
+
+ }
+
+ // Color reduction factor
+ // The comparaison will be made on images with
+ // color space reduced by this factor in each dimension
+ void setColorReduction( int factor) {
+
+ div= factor;
+ }
+
+ int getColorReduction() {
+
+ return div;
+ }
+
+ void setReferenceImage(const cv::Mat& image) {
+
+ reference= hist.colorReduce(image,div);
+ refH= hist.getHistogram(reference);
+ }
+
+ double compare(const cv::Mat& image) {
+
+ input= hist.colorReduce(image,div);
+ inputH= hist.getHistogram(input);
+
+ return cv::compareHist(refH,inputH,CV_COMP_CHISQR);
+ }
+};
+
+
+#endif
|
