summaryrefslogtreecommitdiff
path: root/cvtest/src/imageComparator.h
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2012-05-14 19:00:08 +0100
committerTim Redfern <tim@eclectronics.org>2012-05-14 19:00:08 +0100
commitdbf9692b03ac2485f771993184222f7170e71cf2 (patch)
tree9a17e44304856b5daa9d91172eb40f6e1783b1da /cvtest/src/imageComparator.h
parente333ec0659a74899fbd75c5ed490089d0fd7d244 (diff)
working on background segmentation
Diffstat (limited to 'cvtest/src/imageComparator.h')
-rwxr-xr-xcvtest/src/imageComparator.h71
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