aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorN.N. <sevyves@users.sourceforge.net>2009-07-04 16:30:51 +0000
committerN.N. <sevyves@users.sourceforge.net>2009-07-04 16:30:51 +0000
commit19ba359f3bac851ce20b952bf14ca23c6db1495f (patch)
tree5793ac36322b291863ed886f6dec132c0195b349
parent4f34066a74355dec135501556d7ef270a171ca74 (diff)
added pix_opencv_histo
svn path=/trunk/externals/pix_opencv/; revision=11848
-rw-r--r--Makefile2
-rwxr-xr-xpix_opencv_dft-help.pd14
-rwxr-xr-xpix_opencv_histo-help.pd100
-rwxr-xr-xpix_opencv_histo.cc510
-rwxr-xr-xpix_opencv_histo.h88
-rwxr-xr-xpix_opencv_lk.cc4
6 files changed, 708 insertions, 10 deletions
diff --git a/Makefile b/Makefile
index 9b88ef7..358fe44 100644
--- a/Makefile
+++ b/Makefile
@@ -36,7 +36,7 @@ endif
.SUFFIXES = $(EXTENSION)
-SOURCES = pix_opencv_edge.cc pix_opencv_laplace.cc pix_opencv_morphology.cc pix_opencv_distrans.cc pix_opencv_motempl.cc pix_opencv_haarcascade.cc pix_opencv_contours_boundingrect.cc pix_opencv_bgsubstract.cc pix_opencv_contours_convexity.cc pix_opencv_dft.cc pix_opencv_lk.cc
+SOURCES = pix_opencv_edge.cc pix_opencv_laplace.cc pix_opencv_morphology.cc pix_opencv_distrans.cc pix_opencv_motempl.cc pix_opencv_haarcascade.cc pix_opencv_contours_boundingrect.cc pix_opencv_bgsubstract.cc pix_opencv_contours_convexity.cc pix_opencv_dft.cc pix_opencv_lk.cc pix_opencv_histo.cc
all: $(SOURCES:.cc=.$(EXTENSION))
diff --git a/pix_opencv_dft-help.pd b/pix_opencv_dft-help.pd
index 1963806..6cdde50 100755
--- a/pix_opencv_dft-help.pd
+++ b/pix_opencv_dft-help.pd
@@ -1,7 +1,7 @@
-#N canvas 36 143 1154 642 10;
+#N canvas 41 167 1154 642 10;
#X obj 396 -37 gemhead;
-#X obj 364 351 pix_texture;
-#X obj 364 379 square 2;
+#X obj 365 370 pix_texture;
+#X obj 365 398 square 2;
#X obj 9 -28 cnv 15 220 70 empty empty empty 20 12 0 14 -195568 -66577
0;
#N canvas 0 22 454 304 gemwin 0;
@@ -36,8 +36,8 @@
#X obj 200 368 pix_texture;
#X obj 200 396 square 2;
#X obj 367 159 translateXYZ -2 0 0;
-#X obj 367 224 separator;
-#X obj 499 -71 cnv 15 155 250 empty empty empty 20 12 0 14 -24198 -66577
+#X obj 367 193 separator;
+#X obj 343 221 cnv 15 600 100 empty empty empty 20 12 0 14 -24198 -66577
0;
#X obj 511 -66 bng 25 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
-1;
@@ -52,10 +52,10 @@
#X msg 511 -17 open \$1;
#X obj 499 92 pix_film;
#X msg 517 26 auto \$1;
-#X obj 517 8 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 1 1
+#X obj 517 8 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1
;
#X obj 364 259 translateXYZ 4 0 0;
-#X obj 364 316 pix_opencv_dft;
+#X obj 365 335 pix_opencv_dft;
#X text 8 -64 written by yves degoyon ( ydegoyon@gmail.com );
#X text 9 -80 this can be used for pattern matching;
#X text 9 -94 pix_opencv_dft : discrete fourier transform;
diff --git a/pix_opencv_histo-help.pd b/pix_opencv_histo-help.pd
new file mode 100755
index 0000000..5dd00c9
--- /dev/null
+++ b/pix_opencv_histo-help.pd
@@ -0,0 +1,100 @@
+#N canvas 36 143 1154 642 10;
+#X obj 396 -37 gemhead;
+#X obj 364 372 pix_texture;
+#X obj 364 400 square 2;
+#X obj 9 -28 cnv 15 220 70 empty empty empty 20 12 0 14 -195568 -66577
+0;
+#N canvas 0 22 454 304 gemwin 0;
+#X obj 132 136 gemwin;
+#X obj 67 89 outlet;
+#X obj 67 10 inlet;
+#X obj 67 41 route create;
+#X msg 67 70 set destroy;
+#X msg 182 68 set create;
+#X msg 132 112 create \, 1;
+#X msg 238 112 destroy;
+#N canvas 87 154 247 179 Gem.init 0;
+#X obj 118 46 loadbang;
+#X msg 118 81 reset;
+#X obj 118 113 outlet;
+#X connect 0 0 1 0;
+#X connect 1 0 2 0;
+#X restore 289 80 pd Gem.init;
+#X connect 2 0 3 0;
+#X connect 3 0 4 0;
+#X connect 3 0 6 0;
+#X connect 3 1 5 0;
+#X connect 3 1 7 0;
+#X connect 4 0 1 0;
+#X connect 5 0 1 0;
+#X connect 6 0 0 0;
+#X connect 7 0 0 0;
+#X connect 8 0 0 0;
+#X restore 14 16 pd gemwin;
+#X msg 14 -8 destroy;
+#X text 15 -26 Create window and render;
+#X obj 200 368 pix_texture;
+#X obj 200 396 square 2;
+#X obj 367 159 translateXYZ -2 0 0;
+#X obj 367 224 separator;
+#X obj 350 285 cnv 15 500 80 empty empty empty 20 12 0 14 -24198 -66577
+0;
+#X obj 511 -66 bng 25 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
+-1;
+#X obj 524 128 unpack 0 0 0;
+#X floatatom 514 151 5 0 0 3 length - -;
+#X floatatom 563 151 5 0 0 3 width - -;
+#X floatatom 613 151 5 0 0 3 height - -;
+#X obj 568 109 bng 15 250 50 0 empty empty end_reached 20 7 0 10 -262144
+-1 -1;
+#X floatatom 550 74 5 0 10000 1 frame# - -;
+#X obj 511 -37 openpanel;
+#X msg 511 -17 open \$1;
+#X obj 499 92 pix_film;
+#X msg 517 26 auto \$1;
+#X obj 517 8 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1
+;
+#X obj 364 259 translateXYZ 4 0 0;
+#X obj 580 26 loadbang;
+#X msg 528 50 colorspace RGBA;
+#X floatatom 456 349 5 0 0 0 - - -;
+#X obj 439 290 hradio 15 1 0 5 empty empty empty 0 -8 0 10 -262144
+-1 -1 0;
+#X text 522 289 save an histogram at position nth ( 0 <= n <= 80 )
+;
+#X text 496 350 closest histogram;
+#X obj 364 315 pix_opencv_histo;
+#X text 5 -87 record histograms of specific situations;
+#X text 7 -75 the object will recognize the situations if they occur
+again;
+#X text 7 -61 Written by Lluis Gomez i Bigorda ( lluisgomez@hangar.org
+);
+#X text 6 -100 pix_opencv_histo : image recognition using histograms
+;
+#X connect 0 0 21 0;
+#X connect 1 0 2 0;
+#X connect 4 0 5 0;
+#X connect 5 0 4 0;
+#X connect 7 0 8 0;
+#X connect 9 0 7 0;
+#X connect 9 0 10 0;
+#X connect 10 0 24 0;
+#X connect 12 0 19 0;
+#X connect 13 0 14 0;
+#X connect 13 1 15 0;
+#X connect 13 2 16 0;
+#X connect 17 0 18 0;
+#X connect 18 0 21 1;
+#X connect 19 0 20 0;
+#X connect 20 0 21 0;
+#X connect 21 0 9 0;
+#X connect 21 1 13 0;
+#X connect 21 2 17 0;
+#X connect 22 0 21 0;
+#X connect 23 0 22 0;
+#X connect 24 0 31 0;
+#X connect 25 0 26 0;
+#X connect 26 0 21 0;
+#X connect 28 0 31 1;
+#X connect 31 0 1 0;
+#X connect 31 1 27 0;
diff --git a/pix_opencv_histo.cc b/pix_opencv_histo.cc
new file mode 100755
index 0000000..5bd5758
--- /dev/null
+++ b/pix_opencv_histo.cc
@@ -0,0 +1,510 @@
+////////////////////////////////////////////////////////
+//
+// GEM - Graphics Environment for Multimedia
+//
+// zmoelnig@iem.kug.ac.at
+//
+// Implementation file
+//
+// Copyright (c) 1997-2000 Mark Danks.
+// Copyright (c) Günther Geiger.
+// Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::für::umläute. IEM
+// Copyright (c) 2002 James Tittle & Chris Clepper
+// For information on usage and redistribution, and for a DISCLAIMER OF ALL
+// WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution.
+//
+/////////////////////////////////////////////////////////
+
+#include "pix_opencv_histo.h"
+
+CPPEXTERN_NEW(pix_opencv_histo)
+
+/////////////////////////////////////////////////////////
+//
+// pix_opencv_histo
+//
+/////////////////////////////////////////////////////////
+// Constructor
+//
+/////////////////////////////////////////////////////////
+
+pix_opencv_histo :: pix_opencv_histo()
+{
+ int i;
+
+ comp_xsize=320;
+ comp_ysize=240;
+
+ inlet_new(this->x_obj, &this->x_obj->ob_pd, gensym("float"), gensym("save"));
+ m_dataout = outlet_new(this->x_obj, &s_anything);
+
+ rgba = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 4);
+ rgb = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 3);
+ grey = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ hsv = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 3 );
+
+ h_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ s_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ v_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ planes[0] = h_plane;
+ planes[1] = s_plane;
+ cvCvtPixToPlane( hsv, h_plane, s_plane, v_plane, 0 );
+ h_saved_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ s_saved_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ v_saved_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ saved_planes[0] = h_saved_plane;
+ saved_planes[1] = s_saved_plane;
+
+ int h_bins = (int)(comp_xsize/10), s_bins = (int)(comp_ysize/10);
+ {
+ int hist_size[] = { h_bins, s_bins };
+ float h_ranges[] = { 0, 180 }; // hue is [0,180]
+ float s_ranges[] = { 0, 255 };
+ float* ranges[] = { h_ranges, s_ranges };
+ hist = cvCreateHist(
+ 2,
+ hist_size,
+ CV_HIST_ARRAY,
+ ranges,
+ 1
+ );
+ int n;
+ for (n=0; n<MAX_HISTOGRAMS_TO_COMPARE; n++) {
+ saved_hist[n] = cvCreateHist(
+ 2,
+ hist_size,
+ CV_HIST_ARRAY,
+ ranges,
+ 1
+ );
+ }
+ }
+}
+
+/////////////////////////////////////////////////////////
+// Destructor
+//
+/////////////////////////////////////////////////////////
+pix_opencv_histo :: ~pix_opencv_histo()
+{
+ //Destroy cv_images to clean memory
+ cvReleaseImage(&rgba);
+ cvReleaseImage(&rgb);
+ cvReleaseImage(&grey);
+ cvReleaseImage(&h_plane);
+ cvReleaseImage(&s_plane);
+ cvReleaseImage(&v_plane);
+ cvReleaseImage(&h_saved_plane);
+ cvReleaseImage(&s_saved_plane);
+ cvReleaseImage(&v_saved_plane);
+
+}
+
+/////////////////////////////////////////////////////////
+// processImage
+//
+/////////////////////////////////////////////////////////
+void pix_opencv_histo :: processRGBAImage(imageStruct &image)
+{
+ int i;
+ int h_bins = (int)(comp_xsize/10), s_bins = (int)(comp_ysize/10);
+
+ if ((this->comp_xsize!=image.xsize)&&(this->comp_ysize!=image.ysize)) {
+
+ this->comp_xsize=image.xsize;
+ this->comp_ysize=image.ysize;
+
+ //Destroy cv_images to clean memory
+ cvReleaseImage(&rgba);
+ cvReleaseImage(&rgb);
+ cvReleaseImage(&grey);
+ cvReleaseImage(&h_plane);
+ cvReleaseImage(&s_plane);
+ cvReleaseImage(&v_plane);
+ cvReleaseImage(&h_saved_plane);
+ cvReleaseImage(&s_saved_plane);
+ cvReleaseImage(&v_saved_plane);
+
+ //Create cv_images
+ rgba = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 4);
+ rgb = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 3);
+ grey = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ hsv = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 3 );
+
+ h_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ s_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ v_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ planes[0] = h_plane;
+ planes[1] = s_plane;
+ cvCvtPixToPlane( hsv, h_plane, s_plane, v_plane, 0 );
+ h_saved_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ s_saved_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ v_saved_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ saved_planes[0] = h_saved_plane;
+ saved_planes[1] = s_saved_plane;
+
+ h_bins = (int)(comp_xsize/10);
+ s_bins = (int)(comp_ysize/10);
+ {
+ int hist_size[] = { h_bins, s_bins };
+ float h_ranges[] = { 0, 180 }; // hue is [0,180]
+ float s_ranges[] = { 0, 255 };
+ float* ranges[] = { h_ranges, s_ranges };
+ hist = cvCreateHist(
+ 2,
+ hist_size,
+ CV_HIST_ARRAY,
+ ranges,
+ 1
+ );
+ int n;
+ for (n=0; n<MAX_HISTOGRAMS_TO_COMPARE; n++) {
+ saved_hist[n] = cvCreateHist(
+ 2,
+ hist_size,
+ CV_HIST_ARRAY,
+ ranges,
+ 1
+ );
+ }
+ }
+
+ }
+
+ memcpy( rgba->imageData, image.data, image.xsize*image.ysize*4 );
+
+ // Convert to hsv
+ cvCvtColor( rgba, rgb, CV_BGRA2BGR );
+ cvCvtColor( rgb, hsv, CV_BGR2HSV );
+ cvCvtPixToPlane( hsv, h_plane, s_plane, v_plane, 0 );
+
+ // Build the histogram and compute its contents.
+ if (save_now>=0) {
+ post("saving histogram %d\n",save_now);
+ cvCvtPixToPlane( hsv, h_saved_plane, s_saved_plane, v_saved_plane, 0 );
+ cvCalcHist( saved_planes, saved_hist[save_now], 0, 0 ); //Compute histogram
+ cvNormalizeHist( saved_hist[save_now], 1.0 ); //Normalize it
+ save_now=-1;
+ nbsaved++;
+ }
+ cvCalcHist( planes, hist, 0, 0 ); //Compute histogram
+ cvNormalizeHist( hist, 1.0 ); //Normalize it
+
+ double tato[MAX_HISTOGRAMS_TO_COMPARE];
+ int nearest = -1;
+ double max = 0;
+
+ int n;
+ if ( nbsaved > 0 )
+ for (n=0; n<MAX_HISTOGRAMS_TO_COMPARE; n++) {
+ tato[n] = cvCompareHist(hist, saved_hist[n], CV_COMP_INTERSECT);
+ if (tato[n]>max) {
+ max = tato[n];
+ nearest = n;
+ }
+ }
+
+ outlet_float(m_dataout, (float)nearest);
+
+ // Create an image to use to visualize our histogram.
+ int scale = 10;
+ // populate our visualization with little gray squares.
+ float max_value = 0;
+ cvGetMinMaxHistValue( hist, 0, &max_value, 0, 0 );
+
+ int h = 0;
+ int s = 0;
+
+ for( h = 0; h < h_bins; h++ ) {
+ for( s = 0; s < s_bins; s++ ) {
+ float bin_val = cvQueryHistValue_2D( hist, h, s );
+ int intensity = cvRound( bin_val * 255 / max_value );
+ cvRectangle(
+ rgba,
+ cvPoint( h*scale, s*scale ),
+ cvPoint( (h+1)*scale - 1, (s+1)*scale - 1),
+ CV_RGB(intensity,intensity,intensity), CV_FILLED, 8 , 0 );
+ }
+ }
+
+ memcpy( image.data, rgba->imageData, image.xsize*image.ysize*4 );
+
+}
+
+void pix_opencv_histo :: processRGBImage(imageStruct &image)
+{
+ int i;
+ int h_bins = (int)(comp_xsize/10), s_bins = (int)(comp_ysize/10);
+
+ if ((this->comp_xsize!=image.xsize)&&(this->comp_ysize!=image.ysize)) {
+
+ this->comp_xsize=image.xsize;
+ this->comp_ysize=image.ysize;
+
+ //Destroy cv_images to clean memory
+ cvReleaseImage(&rgba);
+ cvReleaseImage(&rgb);
+ cvReleaseImage(&grey);
+ cvReleaseImage(&h_plane);
+ cvReleaseImage(&s_plane);
+ cvReleaseImage(&v_plane);
+ cvReleaseImage(&h_saved_plane);
+ cvReleaseImage(&s_saved_plane);
+ cvReleaseImage(&v_saved_plane);
+
+ //Create cv_images
+ rgba = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 4);
+ rgb = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 3);
+ grey = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ hsv = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 3 );
+
+ h_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ s_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ v_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ planes[0] = h_plane;
+ planes[1] = s_plane;
+ cvCvtPixToPlane( hsv, h_plane, s_plane, v_plane, 0 );
+ h_saved_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ s_saved_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ v_saved_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ saved_planes[0] = h_saved_plane;
+ saved_planes[1] = s_saved_plane;
+
+ h_bins = (int)(comp_xsize/10);
+ s_bins = (int)(comp_ysize/10);
+ {
+ int hist_size[] = { h_bins, s_bins };
+ float h_ranges[] = { 0, 180 }; // hue is [0,180]
+ float s_ranges[] = { 0, 255 };
+ float* ranges[] = { h_ranges, s_ranges };
+ hist = cvCreateHist(
+ 2,
+ hist_size,
+ CV_HIST_ARRAY,
+ ranges,
+ 1
+ );
+ int n;
+ for (n=0; n<MAX_HISTOGRAMS_TO_COMPARE; n++) {
+ saved_hist[n] = cvCreateHist(
+ 2,
+ hist_size,
+ CV_HIST_ARRAY,
+ ranges,
+ 1
+ );
+ }
+ }
+
+ }
+
+ memcpy( rgb->imageData, image.data, image.xsize*image.ysize*3 );
+
+ // Convert to hsv
+ cvCvtColor( rgb, hsv, CV_BGR2HSV );
+ cvCvtPixToPlane( hsv, h_plane, s_plane, v_plane, 0 );
+
+ // Build the histogram and compute its contents.
+ if (save_now>=0) {
+ post("saving histogram %d\n",save_now);
+ cvCvtPixToPlane( hsv, h_saved_plane, s_saved_plane, v_saved_plane, 0 );
+ cvCalcHist( saved_planes, saved_hist[save_now], 0, 0 ); //Compute histogram
+ cvNormalizeHist( saved_hist[save_now], 1.0 ); //Normalize it
+ save_now=-1;
+ nbsaved++;
+ }
+ cvCalcHist( planes, hist, 0, 0 ); //Compute histogram
+ cvNormalizeHist( hist, 1.0 ); //Normalize it
+
+ double tato[MAX_HISTOGRAMS_TO_COMPARE];
+ int nearest = -1;
+ double max = 0;
+
+ int n;
+ if ( nbsaved > 0 )
+ for (n=0; n<MAX_HISTOGRAMS_TO_COMPARE; n++) {
+ tato[n] = cvCompareHist(hist, saved_hist[n], CV_COMP_INTERSECT);
+ if (tato[n]>max) {
+ max = tato[n];
+ nearest = n;
+ }
+ }
+
+ outlet_float(m_dataout, (float)nearest);
+
+ // Create an image to use to visualize our histogram.
+ int scale = 10;
+ // populate our visualization with little gray squares.
+ float max_value = 0;
+ cvGetMinMaxHistValue( hist, 0, &max_value, 0, 0 );
+
+ int h = 0;
+ int s = 0;
+
+ for( h = 0; h < h_bins; h++ ) {
+ for( s = 0; s < s_bins; s++ ) {
+ float bin_val = cvQueryHistValue_2D( hist, h, s );
+ int intensity = cvRound( bin_val * 255 / max_value );
+ cvRectangle(
+ rgb,
+ cvPoint( h*scale, s*scale ),
+ cvPoint( (h+1)*scale - 1, (s+1)*scale - 1),
+ CV_RGB(intensity,intensity,intensity), CV_FILLED, 8 , 0 );
+ }
+ }
+
+ memcpy( image.data, rgb->imageData, image.xsize*image.ysize*3 );
+
+}
+
+void pix_opencv_histo :: processYUVImage(imageStruct &image)
+{
+}
+
+void pix_opencv_histo :: processGrayImage(imageStruct &image)
+{
+ int i;
+ int h_bins = (int)(comp_xsize/10), s_bins = (int)(comp_ysize/10);
+
+ if ((this->comp_xsize!=image.xsize)&&(this->comp_ysize!=image.ysize)) {
+
+ this->comp_xsize=image.xsize;
+ this->comp_ysize=image.ysize;
+
+ //Destroy cv_images to clean memory
+ cvReleaseImage(&rgba);
+ cvReleaseImage(&rgb);
+ cvReleaseImage(&grey);
+ cvReleaseImage(&h_plane);
+ cvReleaseImage(&s_plane);
+ cvReleaseImage(&v_plane);
+ cvReleaseImage(&h_saved_plane);
+ cvReleaseImage(&s_saved_plane);
+ cvReleaseImage(&v_saved_plane);
+
+ //Create cv_images
+ rgba = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 4);
+ rgb = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 3);
+ grey = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ hsv = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 3 );
+
+ h_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ s_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ v_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ planes[0] = h_plane;
+ planes[1] = s_plane;
+ cvCvtPixToPlane( hsv, h_plane, s_plane, v_plane, 0 );
+ h_saved_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ s_saved_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ v_saved_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ saved_planes[0] = h_saved_plane;
+ saved_planes[1] = s_saved_plane;
+
+ h_bins = (int)(comp_xsize/10);
+ s_bins = (int)(comp_ysize/10);
+ {
+ int hist_size[] = { h_bins, s_bins };
+ float h_ranges[] = { 0, 180 }; // hue is [0,180]
+ float s_ranges[] = { 0, 255 };
+ float* ranges[] = { h_ranges, s_ranges };
+ hist = cvCreateHist(
+ 2,
+ hist_size,
+ CV_HIST_ARRAY,
+ ranges,
+ 1
+ );
+ int n;
+ for (n=0; n<MAX_HISTOGRAMS_TO_COMPARE; n++) {
+ saved_hist[n] = cvCreateHist(
+ 2,
+ hist_size,
+ CV_HIST_ARRAY,
+ ranges,
+ 1
+ );
+ }
+ }
+
+ }
+
+ memcpy( grey->imageData, image.data, image.xsize*image.ysize );
+
+ // Convert to hsv
+ cvCvtColor( grey, rgb, CV_GRAY2BGR );
+ cvCvtColor( rgb, hsv, CV_BGR2HSV );
+ cvCvtPixToPlane( hsv, h_plane, s_plane, v_plane, 0 );
+
+ // Build the histogram and compute its contents.
+ if (save_now>=0) {
+ post("saving histogram %d\n",save_now);
+ cvCvtPixToPlane( hsv, h_saved_plane, s_saved_plane, v_saved_plane, 0 );
+ cvCalcHist( saved_planes, saved_hist[save_now], 0, 0 ); //Compute histogram
+ cvNormalizeHist( saved_hist[save_now], 1.0 ); //Normalize it
+ save_now=-1;
+ nbsaved++;
+ }
+ cvCalcHist( planes, hist, 0, 0 ); //Compute histogram
+ cvNormalizeHist( hist, 1.0 ); //Normalize it
+
+ double tato[MAX_HISTOGRAMS_TO_COMPARE];
+ int nearest = -1;
+ double max = 0;
+
+ int n;
+ if ( nbsaved > 0 )
+ for (n=0; n<MAX_HISTOGRAMS_TO_COMPARE; n++) {
+ tato[n] = cvCompareHist(hist, saved_hist[n], CV_COMP_INTERSECT);
+ if (tato[n]>max) {
+ max = tato[n];
+ nearest = n;
+ }
+ }
+
+ outlet_float(m_dataout, (float)nearest);
+
+ // Create an image to use to visualize our histogram.
+ int scale = 10;
+ // populate our visualization with little gray squares.
+ float max_value = 0;
+ cvGetMinMaxHistValue( hist, 0, &max_value, 0, 0 );
+
+ int h = 0;
+ int s = 0;
+
+ for( h = 0; h < h_bins; h++ ) {
+ for( s = 0; s < s_bins; s++ ) {
+ float bin_val = cvQueryHistValue_2D( hist, h, s );
+ int intensity = cvRound( bin_val * 255 / max_value );
+ cvRectangle(
+ grey,
+ cvPoint( h*scale, s*scale ),
+ cvPoint( (h+1)*scale - 1, (s+1)*scale - 1),
+ CV_RGB(intensity,intensity,intensity), CV_FILLED, 8 , 0 );
+ }
+ }
+
+ memcpy( image.data, grey->imageData, image.xsize*image.ysize );
+
+}
+
+/////////////////////////////////////////////////////////
+// static member function
+//
+/////////////////////////////////////////////////////////
+
+void pix_opencv_histo :: obj_setupCallback(t_class *classPtr)
+{
+ class_addmethod(classPtr, (t_method)&pix_opencv_histo::saveMessCallback,
+ gensym("save"), A_FLOAT, A_NULL);
+}
+
+void pix_opencv_histo :: saveMess(float index)
+{
+ if (((int)index>=0)&&((int)index<MAX_HISTOGRAMS_TO_COMPARE)) save_now = (int)index;
+}
+
+void pix_opencv_histo :: saveMessCallback(void *data, t_floatarg index)
+{
+ GetMyClass(data)->saveMess(index);
+}
diff --git a/pix_opencv_histo.h b/pix_opencv_histo.h
new file mode 100755
index 0000000..900a18b
--- /dev/null
+++ b/pix_opencv_histo.h
@@ -0,0 +1,88 @@
+/*-----------------------------------------------------------------
+LOG
+ GEM - Graphics Environment for Multimedia
+
+ Change pix to greyscale
+
+ Copyright (c) 1997-1999 Mark Danks. mark@danks.org
+ Copyright (c) Günther Geiger. geiger@epy.co.at
+ Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::für::umläute. IEM. zmoelnig@iem.kug.ac.at
+ Copyright (c) 2002 James Tittle & Chris Clepper
+ For information on usage and redistribution, and for a DISCLAIMER OF ALL
+ WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution.
+
+-----------------------------------------------------------------*/
+
+#ifndef INCLUDE_PIX_OPENCV_DISTRANS_H_
+#define INCLUDE_PIX_OPENCV_DISTRANS_H_
+
+#include "Base/GemPixObj.h"
+
+#ifndef _EiC
+#include "cv.h"
+#endif
+
+#define MAX_HISTOGRAMS_TO_COMPARE 80
+
+/*-----------------------------------------------------------------
+-------------------------------------------------------------------
+CLASS
+ pix_opencv_histo
+
+ Histogram reognition object using Open CV
+
+KEYWORDS
+ pix
+
+DESCRIPTION
+
+-----------------------------------------------------------------*/
+
+class GEM_EXTERN pix_opencv_histo : public GemPixObj
+{
+ CPPEXTERN_HEADER(pix_opencv_histo, GemPixObj)
+
+ public:
+
+ //////////
+ // Constructor
+ pix_opencv_histo();
+
+ protected:
+
+ //////////
+ // Destructor
+ virtual ~pix_opencv_histo();
+
+ //////////
+ // Do the processing
+ virtual void processRGBAImage(imageStruct &image);
+ virtual void processRGBImage(imageStruct &image);
+ virtual void processYUVImage(imageStruct &image);
+ virtual void processGrayImage(imageStruct &image);
+
+ void saveMess(float index);
+
+ int comp_xsize;
+ int comp_ysize;
+
+ t_outlet *m_dataout;
+
+ private:
+
+ //////////
+ // Static member functions
+ static void saveMessCallback(void *data, t_floatarg index);
+
+ // The output and temporary images
+ int save_now;
+ int nbsaved;
+
+ CvHistogram *hist;
+ CvHistogram *saved_hist[MAX_HISTOGRAMS_TO_COMPARE];
+ IplImage *rgba, *rgb, *grey, *hsv, *h_plane, *s_plane, *v_plane, *h_saved_plane, *s_saved_plane, *v_saved_plane, *planes[2],*saved_planes[2];
+
+
+};
+
+#endif // for header file
diff --git a/pix_opencv_lk.cc b/pix_opencv_lk.cc
index a4a7acb..1d1f429 100755
--- a/pix_opencv_lk.cc
+++ b/pix_opencv_lk.cc
@@ -33,8 +33,8 @@ pix_opencv_lk :: pix_opencv_lk()
{
int i;
- comp_xsize=0;
- comp_ysize=0;
+ comp_xsize=320;
+ comp_ysize=240;
inlet_new(this->x_obj, &this->x_obj->ob_pd, gensym("float"), gensym("winsize"));