aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorN.N. <sevyves@users.sourceforge.net>2009-08-29 19:03:18 +0000
committerN.N. <sevyves@users.sourceforge.net>2009-08-29 19:03:18 +0000
commit9ccaf6ebab9d445e5b8ed04f58956cacb7ac7467 (patch)
treebd3f768fb935bb7a2eb638ce2ce3e046fdba1022
parent59a807306733cc1a93f5f6a0c57e3074e40c716a (diff)
rename histo to hist_compare
svn path=/trunk/externals/pix_opencv/; revision=12136
-rw-r--r--Makefile2
-rwxr-xr-xpix_opencv_hist_compare-help.pd (renamed from pix_opencv_histo-help.pd)44
-rwxr-xr-xpix_opencv_hist_compare.cc (renamed from pix_opencv_histo.cc)95
-rwxr-xr-xpix_opencv_hist_compare.h (renamed from pix_opencv_histo.h)11
4 files changed, 94 insertions, 58 deletions
diff --git a/Makefile b/Makefile
index 8fc259e..1deb95f 100644
--- a/Makefile
+++ b/Makefile
@@ -35,7 +35,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 pix_opencv_histo.cc pix_opencv_knear.cc pix_opencv_threshold.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_hist_compare.cc pix_opencv_knear.cc pix_opencv_threshold.cc
all: $(SOURCES:.cc=.$(EXTENSION))
diff --git a/pix_opencv_histo-help.pd b/pix_opencv_hist_compare-help.pd
index 5dd00c9..17268b7 100755
--- a/pix_opencv_histo-help.pd
+++ b/pix_opencv_hist_compare-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 372 pix_texture;
-#X obj 364 400 square 2;
+#X obj 364 478 pix_texture;
+#X obj 364 506 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;
@@ -33,11 +33,11 @@
#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 216 478 pix_texture;
+#X obj 216 506 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
+#X obj 350 285 cnv 15 500 180 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;
@@ -57,19 +57,30 @@
#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 floatatom 443 421 5 0 0 0 - - -;
+#X obj 505 346 unpack f f f f f;
+#X text 598 381 nearest to 1 is the winner;
+#X text 479 422 closest histogram (winner);
+#X obj 505 374 vsl 15 37 0 1 0 0 empty empty empty 0 -9 0 10 -262144
+-1 -1 0 1;
+#X obj 528 374 vsl 15 37 0 1 0 0 empty empty empty 0 -9 0 10 -262144
+-1 -1 0 1;
+#X obj 551 374 vsl 15 37 0 1 0 0 empty empty empty 0 -9 0 10 -262144
+-1 -1 0 1;
+#X obj 574 374 vsl 15 37 0 1 0 0 empty empty empty 0 -9 0 10 -262144
+-1 -1 0 1;
+#X text 597 370 matching measure with stored histograms;
+#X obj 364 315 pix_opencv_hist_compare;
+#X text 7 -100 pix_opencv_hist_compare : image recognition using histograms
;
#X connect 0 0 21 0;
#X connect 1 0 2 0;
@@ -92,9 +103,14 @@ again;
#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 24 0 41 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;
+#X connect 27 0 41 1;
+#X connect 33 0 36 0;
+#X connect 33 1 37 0;
+#X connect 33 2 38 0;
+#X connect 33 3 39 0;
+#X connect 41 0 1 0;
+#X connect 41 1 32 0;
+#X connect 41 2 33 0;
diff --git a/pix_opencv_histo.cc b/pix_opencv_hist_compare.cc
index c5000ce..865b090 100755
--- a/pix_opencv_histo.cc
+++ b/pix_opencv_hist_compare.cc
@@ -15,20 +15,20 @@
//
/////////////////////////////////////////////////////////
-#include "pix_opencv_histo.h"
+#include "pix_opencv_hist_compare.h"
-CPPEXTERN_NEW(pix_opencv_histo)
+CPPEXTERN_NEW(pix_opencv_hist_compare)
/////////////////////////////////////////////////////////
//
-// pix_opencv_histo
+// pix_opencv_hist_compare
//
/////////////////////////////////////////////////////////
// Constructor
//
/////////////////////////////////////////////////////////
-pix_opencv_histo :: pix_opencv_histo()
+pix_opencv_hist_compare :: pix_opencv_hist_compare()
{
int i;
@@ -37,6 +37,7 @@ pix_opencv_histo :: pix_opencv_histo()
inlet_new(this->x_obj, &this->x_obj->ob_pd, gensym("float"), gensym("save"));
m_dataout = outlet_new(this->x_obj, &s_anything);
+ m_measureout = outlet_new(this->x_obj, &s_anything);
save_now = 0;
@@ -86,7 +87,7 @@ pix_opencv_histo :: pix_opencv_histo()
// Destructor
//
/////////////////////////////////////////////////////////
-pix_opencv_histo :: ~pix_opencv_histo()
+pix_opencv_hist_compare :: ~pix_opencv_hist_compare()
{
//Destroy cv_images to clean memory
cvReleaseImage(&rgba);
@@ -105,7 +106,7 @@ pix_opencv_histo :: ~pix_opencv_histo()
// processImage
//
/////////////////////////////////////////////////////////
-void pix_opencv_histo :: processRGBAImage(imageStruct &image)
+void pix_opencv_hist_compare :: processRGBAImage(imageStruct &image)
{
int i;
int h_bins = (int)(comp_xsize/10), s_bins = (int)(comp_ysize/10);
@@ -115,7 +116,7 @@ void pix_opencv_histo :: processRGBAImage(imageStruct &image)
this->comp_xsize=image.xsize;
this->comp_ysize=image.ysize;
- post( "pix_opencv_histo : reallocating buffers" );
+ post( "pix_opencv_hist_compare : reallocating buffers" );
//Destroy cv_images to clean memory
cvReleaseImage(&rgba);
@@ -194,6 +195,7 @@ void pix_opencv_histo :: processRGBAImage(imageStruct &image)
cvNormalizeHist( hist, 1.0 ); //Normalize it
double tato[MAX_HISTOGRAMS_TO_COMPARE];
+ t_atom datalist[MAX_HISTOGRAMS_TO_COMPARE];
int nearest = -1;
double max = 0;
@@ -201,13 +203,18 @@ void pix_opencv_histo :: processRGBAImage(imageStruct &image)
if ( nbsaved > 0 )
for (n=0; n<MAX_HISTOGRAMS_TO_COMPARE; n++) {
tato[n] = cvCompareHist(hist, saved_hist[n], CV_COMP_INTERSECT);
+ SETFLOAT(&datalist[n], tato[n]);
if (tato[n]>max) {
max = tato[n];
nearest = n;
}
}
- outlet_float(m_dataout, (float)nearest);
+ if ( nbsaved > 0 ) {
+ outlet_float(m_dataout, (float)nearest);
+ outlet_list( m_measureout, 0, MAX_HISTOGRAMS_TO_COMPARE , datalist );
+ } else
+ outlet_float(m_dataout, -1.0);
// Create an image to use to visualize our histogram.
int scale = 10;
@@ -234,7 +241,7 @@ void pix_opencv_histo :: processRGBAImage(imageStruct &image)
}
-void pix_opencv_histo :: processRGBImage(imageStruct &image)
+void pix_opencv_hist_compare :: processRGBImage(imageStruct &image)
{
int i;
int h_bins = (int)(comp_xsize/10), s_bins = (int)(comp_ysize/10);
@@ -320,6 +327,7 @@ void pix_opencv_histo :: processRGBImage(imageStruct &image)
cvNormalizeHist( hist, 1.0 ); //Normalize it
double tato[MAX_HISTOGRAMS_TO_COMPARE];
+ t_atom datalist[MAX_HISTOGRAMS_TO_COMPARE];
int nearest = -1;
double max = 0;
@@ -327,13 +335,18 @@ void pix_opencv_histo :: processRGBImage(imageStruct &image)
if ( nbsaved > 0 )
for (n=0; n<MAX_HISTOGRAMS_TO_COMPARE; n++) {
tato[n] = cvCompareHist(hist, saved_hist[n], CV_COMP_INTERSECT);
+ SETFLOAT(&datalist[n], tato[n]);
if (tato[n]>max) {
max = tato[n];
nearest = n;
}
}
- outlet_float(m_dataout, (float)nearest);
+ if ( nbsaved > 0 ) {
+ outlet_float(m_dataout, (float)nearest);
+ outlet_list( m_measureout, 0, MAX_HISTOGRAMS_TO_COMPARE , datalist );
+ } else
+ outlet_float(m_dataout, -1.0);
// Create an image to use to visualize our histogram.
int scale = 10;
@@ -360,12 +373,12 @@ void pix_opencv_histo :: processRGBImage(imageStruct &image)
}
-void pix_opencv_histo :: processYUVImage(imageStruct &image)
+void pix_opencv_hist_compare :: processYUVImage(imageStruct &image)
{
- post( "pix_opencv_histo : yuv format not supported" );
+ post( "pix_opencv_hist_compare : yuv format not supported" );
}
-void pix_opencv_histo :: processGrayImage(imageStruct &image)
+void pix_opencv_hist_compare :: processGrayImage(imageStruct &image)
{
int i;
int h_bins = (int)(comp_xsize/10), s_bins = (int)(comp_ysize/10);
@@ -447,37 +460,43 @@ void pix_opencv_histo :: processGrayImage(imageStruct &image)
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
+ }
+ 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;
+ double tato[MAX_HISTOGRAMS_TO_COMPARE];
+ t_atom datalist[MAX_HISTOGRAMS_TO_COMPARE];
+ int nearest = -1;
+ double max = 0;
- int n;
- if ( nbsaved > 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);
+ SETFLOAT(&datalist[n], tato[n]);
if (tato[n]>max) {
max = tato[n];
nearest = n;
}
- }
+ }
- outlet_float(m_dataout, (float)nearest);
+ if ( nbsaved > 0 ) {
+ outlet_float(m_dataout, (float)nearest);
+ outlet_list( m_measureout, 0, MAX_HISTOGRAMS_TO_COMPARE , datalist );
+ } else
+ outlet_float(m_dataout, -1.0);
- // 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 );
+ // 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;
+ int h = 0;
+ int s = 0;
- for( h = 0; h < h_bins; h++ ) {
- for( s = 0; s < s_bins; s++ ) {
+ 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(
@@ -486,9 +505,9 @@ void pix_opencv_histo :: processGrayImage(imageStruct &image)
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 );
+ memcpy( image.data, grey->imageData, image.xsize*image.ysize );
}
@@ -497,18 +516,18 @@ void pix_opencv_histo :: processGrayImage(imageStruct &image)
//
/////////////////////////////////////////////////////////
-void pix_opencv_histo :: obj_setupCallback(t_class *classPtr)
+void pix_opencv_hist_compare :: obj_setupCallback(t_class *classPtr)
{
- class_addmethod(classPtr, (t_method)&pix_opencv_histo::saveMessCallback,
+ class_addmethod(classPtr, (t_method)&pix_opencv_hist_compare::saveMessCallback,
gensym("save"), A_FLOAT, A_NULL);
}
-void pix_opencv_histo :: saveMess(float index)
+void pix_opencv_hist_compare :: 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)
+void pix_opencv_hist_compare :: saveMessCallback(void *data, t_floatarg index)
{
GetMyClass(data)->saveMess(index);
}
diff --git a/pix_opencv_histo.h b/pix_opencv_hist_compare.h
index ca27166..7e07f0b 100755
--- a/pix_opencv_histo.h
+++ b/pix_opencv_hist_compare.h
@@ -27,7 +27,7 @@ LOG
/*-----------------------------------------------------------------
-------------------------------------------------------------------
CLASS
- pix_opencv_histo
+ pix_opencv_hist_compare
Histogram reognition object using Open CV
@@ -38,21 +38,21 @@ DESCRIPTION
-----------------------------------------------------------------*/
-class GEM_EXTERN pix_opencv_histo : public GemPixObj
+class GEM_EXTERN pix_opencv_hist_compare : public GemPixObj
{
- CPPEXTERN_HEADER(pix_opencv_histo, GemPixObj)
+ CPPEXTERN_HEADER(pix_opencv_hist_compare, GemPixObj)
public:
//////////
// Constructor
- pix_opencv_histo();
+ pix_opencv_hist_compare();
protected:
//////////
// Destructor
- virtual ~pix_opencv_histo();
+ virtual ~pix_opencv_hist_compare();
//////////
// Do the processing
@@ -67,6 +67,7 @@ class GEM_EXTERN pix_opencv_histo : public GemPixObj
int comp_ysize;
t_outlet *m_dataout;
+ t_outlet *m_measureout;
private: