aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorN.N. <sevyves@users.sourceforge.net>2009-09-11 21:45:30 +0000
committerN.N. <sevyves@users.sourceforge.net>2009-09-11 21:45:30 +0000
commit5fbce613e5db654eef74c471e1116131bd414f5f (patch)
tree29cb991e502c08944a7875b5c770462a0656c8bd
parent17ed7b467d52b597664834278fbbfbee8d77c3c1 (diff)
added hu moments
svn path=/trunk/externals/pix_opencv/; revision=12314
-rw-r--r--Makefile4
-rwxr-xr-xpix_opencv_hu_moments-help.pd160
-rwxr-xr-xpix_opencv_hu_moments.cc207
-rwxr-xr-xpix_opencv_hu_moments.h86
4 files changed, 455 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 54b3e3c..3f23b23 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
PD_DIR = ../../pd
-GEM_DIR = ../../Gem
+GEM_DIR = ../gem
GEM_OPENCV_VERSION = 0.1
@@ -27,7 +27,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_hist_compare.cc pix_opencv_knear.cc pix_opencv_threshold.cc pix_opencv_floodfill.cc pix_opencv_athreshold.cc pix_opencv_bgstats.cc pix_opencv_camshift.cc pix_opencv_hu_compare.cc pix_opencv_pgh_compare.cc pix_opencv_hough_circles.cc pix_opencv_hough_lines.cc pix_opencv_surf.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 pix_opencv_floodfill.cc pix_opencv_athreshold.cc pix_opencv_bgstats.cc pix_opencv_camshift.cc pix_opencv_hu_compare.cc pix_opencv_pgh_compare.cc pix_opencv_hough_circles.cc pix_opencv_hough_lines.cc pix_opencv_surf.cc pix_opencv_hu_moments.cc
all: $(SOURCES:.cc=.$(EXTENSION))
diff --git a/pix_opencv_hu_moments-help.pd b/pix_opencv_hu_moments-help.pd
new file mode 100755
index 0000000..e2f5eaa
--- /dev/null
+++ b/pix_opencv_hu_moments-help.pd
@@ -0,0 +1,160 @@
+#N canvas 1 49 820 711 10;
+#X obj 13 0 gemhead;
+#X obj 30 439 pix_texture;
+#X obj 30 467 square 2;
+#X obj 506 536 cnv 15 220 70 empty empty empty 20 12 0 14 -195568 -66577
+0;
+#N canvas 0 22 454 304 gemwin 0;
+#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;
+#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 obj 171 266 gemwin;
+#X msg 164 226 create \, 1;
+#X msg 252 229 destroy;
+#X msg 292 186 frame 5;
+#X obj 173 176 t b b b;
+#X connect 1 0 2 0;
+#X connect 2 0 3 0;
+#X connect 2 0 10 0;
+#X connect 2 1 4 0;
+#X connect 2 1 8 0;
+#X connect 3 0 0 0;
+#X connect 4 0 0 0;
+#X connect 7 0 6 0;
+#X connect 8 0 6 0;
+#X connect 9 0 6 0;
+#X connect 10 0 7 0;
+#X connect 10 2 9 0;
+#X restore 516 580 pd gemwin;
+#X msg 516 562 destroy;
+#X obj 114 -18 bng 25 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
+-1;
+#X obj 114 11 openpanel;
+#X msg 114 31 open \$1;
+#X obj 15 182 cnv 15 400 250 empty empty empty 20 12 0 14 -4034 -66577
+0;
+#X text 514 539 Create window and render;
+#X obj 203 30 loadbang;
+#X msg 203 55 colorspace RGBA;
+#X msg 307 55 colorspace RGB;
+#X msg 266 29 colorspace Grey;
+#X obj 32 235 pix_opencv_hu_moments;
+#X msg 82 197 binary \$1;
+#X obj 152 198 tgl 15 0 sbin empty empty 17 7 0 10 -262144 -1 -1 0
+1;
+#X text 171 198 treat incoming frames as binary data;
+#X text 187 -19 Written by Yves Degoyon ( ydegoyon@gmail.com );
+#X text 186 -67 pix_opencv_hu_moments :: Calculates the hu moments
+of contours.;
+#X obj 135 256 unpack f f f f f f f;
+#X floatatom 145 283 30 0 0 0 - - h1;
+#X text 125 282 h1;
+#X floatatom 156 305 30 0 0 0 - - h2;
+#X floatatom 167 326 30 0 0 0 - - h3;
+#X floatatom 180 347 30 0 0 0 - - h4;
+#X floatatom 196 369 30 0 0 0 - - h5;
+#X floatatom 208 389 30 0 0 0 - - h6;
+#X floatatom 217 412 30 0 0 0 - - h7;
+#X text 136 304 h2;
+#X text 148 325 h3;
+#X text 161 346 h4;
+#X text 176 368 h5;
+#X text 188 388 h6;
+#X text 197 411 h7;
+#X obj 115 104 pix_image;
+#X text 187 -43 Load here with a simple patterns image and compare
+the moments.;
+#X obj 529 -15 bng 25 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
+-1;
+#X obj 529 14 openpanel;
+#X msg 529 34 open \$1;
+#X obj 430 185 cnv 15 400 250 empty empty empty 20 12 0 14 -4034 -66577
+0;
+#X obj 618 33 loadbang;
+#X msg 618 58 colorspace RGBA;
+#X msg 722 58 colorspace RGB;
+#X msg 681 32 colorspace Grey;
+#X obj 447 238 pix_opencv_hu_moments;
+#X msg 497 200 binary \$1;
+#X obj 567 201 tgl 15 0 sbin empty empty 17 7 0 10 -262144 -1 -1 0
+1;
+#X text 593 201 treat incoming frames as binary data;
+#X obj 550 259 unpack f f f f f f f;
+#X floatatom 560 286 30 0 0 0 - - h1;
+#X text 540 285 h1;
+#X floatatom 571 308 30 0 0 0 - - h2;
+#X floatatom 582 329 30 0 0 0 - - h3;
+#X floatatom 595 350 30 0 0 0 - - h4;
+#X floatatom 611 372 30 0 0 0 - - h5;
+#X floatatom 623 392 30 0 0 0 - - h6;
+#X floatatom 632 415 30 0 0 0 - - h7;
+#X text 551 307 h2;
+#X text 563 328 h3;
+#X text 576 349 h4;
+#X text 591 371 h5;
+#X text 603 391 h6;
+#X text 612 414 h7;
+#X obj 484 117 pix_image;
+#X obj 115 133 translateXYZ -2 0 0;
+#X obj 113 162 separator;
+#X obj 447 445 pix_texture;
+#X obj 447 473 square 2;
+#X floatatom 216 100 5 0 0 0 - - -;
+#X obj 191 161 translateXYZ 4 0 0;
+#X connect 0 0 36 0;
+#X connect 1 0 2 0;
+#X connect 4 0 5 0;
+#X connect 5 0 4 0;
+#X connect 6 0 7 0;
+#X connect 7 0 8 0;
+#X connect 8 0 36 0;
+#X connect 11 0 12 0;
+#X connect 12 0 36 0;
+#X connect 13 0 36 0;
+#X connect 14 0 36 0;
+#X connect 15 0 1 0;
+#X connect 15 1 21 0;
+#X connect 16 0 15 0;
+#X connect 17 0 16 0;
+#X connect 21 0 22 0;
+#X connect 21 1 24 0;
+#X connect 21 2 25 0;
+#X connect 21 3 26 0;
+#X connect 21 4 27 0;
+#X connect 21 5 28 0;
+#X connect 21 6 29 0;
+#X connect 36 0 66 0;
+#X connect 38 0 39 0;
+#X connect 39 0 40 0;
+#X connect 40 0 65 0;
+#X connect 42 0 43 0;
+#X connect 43 0 65 0;
+#X connect 44 0 65 0;
+#X connect 45 0 65 0;
+#X connect 46 0 68 0;
+#X connect 46 1 50 0;
+#X connect 47 0 46 0;
+#X connect 48 0 47 0;
+#X connect 50 0 51 0;
+#X connect 50 1 53 0;
+#X connect 50 2 54 0;
+#X connect 50 3 55 0;
+#X connect 50 4 56 0;
+#X connect 50 5 57 0;
+#X connect 50 6 58 0;
+#X connect 65 0 46 0;
+#X connect 66 0 67 0;
+#X connect 66 0 15 0;
+#X connect 67 0 71 0;
+#X connect 68 0 69 0;
+#X connect 70 0 66 1;
+#X connect 71 0 65 0;
diff --git a/pix_opencv_hu_moments.cc b/pix_opencv_hu_moments.cc
new file mode 100755
index 0000000..6665107
--- /dev/null
+++ b/pix_opencv_hu_moments.cc
@@ -0,0 +1,207 @@
+////////////////////////////////////////////////////////
+//
+// 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_hu_moments.h"
+
+CPPEXTERN_NEW(pix_opencv_hu_moments)
+
+/////////////////////////////////////////////////////////
+//
+// pix_opencv_hu_moments
+//
+/////////////////////////////////////////////////////////
+// Constructor
+//
+/////////////////////////////////////////////////////////
+pix_opencv_hu_moments :: pix_opencv_hu_moments()
+{
+ m_dataout = outlet_new(this->x_obj, &s_anything);
+
+ comp_xsize = 320;
+ comp_ysize = 240;
+
+ x_binary = 0;
+
+ rgba = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 4);
+ rgb = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 3);
+ gray = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+
+}
+
+/////////////////////////////////////////////////////////
+// Destructor
+//
+/////////////////////////////////////////////////////////
+pix_opencv_hu_moments :: ~pix_opencv_hu_moments()
+{
+ //Destroy cv_images to clean memory
+ cvReleaseImage(&rgba);
+ cvReleaseImage(&rgb);
+ cvReleaseImage(&gray);
+}
+
+/////////////////////////////////////////////////////////
+// processImage
+//
+/////////////////////////////////////////////////////////
+void pix_opencv_hu_moments :: processRGBAImage(imageStruct &image)
+{
+ if ((this->comp_xsize!=image.xsize)||(this->comp_ysize!=image.ysize)||(!rgba))
+ {
+
+ this->comp_xsize = image.xsize;
+ this->comp_ysize = image.ysize;
+
+ //Destroy cv_images to clean memory
+ if ( rgba )
+ {
+ cvReleaseImage(&rgba);
+ cvReleaseImage(&rgb);
+ cvReleaseImage(&gray);
+ }
+
+ //create the orig image with new size
+ rgba = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 4);
+ rgb = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 3);
+ gray = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 1);
+ }
+
+ memcpy( rgba->imageData, image.data, image.xsize*image.ysize*4 );
+ cvCvtColor(rgba, gray, CV_BGRA2GRAY);
+
+ cvMoments( gray, &x_moments, x_binary );
+ cvGetHuMoments( &x_moments, &x_humoments );
+
+ SETFLOAT(&rlist[0], x_humoments.hu1);
+ SETFLOAT(&rlist[1], x_humoments.hu2);
+ SETFLOAT(&rlist[2], x_humoments.hu3);
+ SETFLOAT(&rlist[3], x_humoments.hu4);
+ SETFLOAT(&rlist[4], x_humoments.hu5);
+ SETFLOAT(&rlist[5], x_humoments.hu6);
+ SETFLOAT(&rlist[6], x_humoments.hu7);
+
+ outlet_list( m_dataout, 0, 7, rlist );
+}
+
+void pix_opencv_hu_moments :: processRGBImage(imageStruct &image)
+{
+ unsigned char *pixels = image.data;
+
+ if ((this->comp_xsize!=image.xsize)||(this->comp_ysize!=image.ysize)||(!rgb)) {
+
+ this->comp_xsize = image.xsize;
+ this->comp_ysize = image.ysize;
+
+ //Destroy cv_images to clean memory
+ if ( rgb )
+ {
+ cvReleaseImage(&rgba);
+ cvReleaseImage(&rgb);
+ cvReleaseImage(&gray);
+ }
+
+ //create the orig image with new size
+ rgba = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 4);
+ rgb = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 3);
+ gray = cvCreateImage(cvSize(rgb->width,rgb->height), IPL_DEPTH_8U, 1);
+
+ }
+ memcpy( rgb->imageData, image.data, image.xsize*image.ysize*3 );
+ cvCvtColor(rgb, gray, CV_RGB2GRAY);
+
+ cvMoments( gray, &x_moments, x_binary );
+ cvGetHuMoments( &x_moments, &x_humoments );
+
+ SETFLOAT(&rlist[0], x_humoments.hu1);
+ SETFLOAT(&rlist[1], x_humoments.hu2);
+ SETFLOAT(&rlist[2], x_humoments.hu3);
+ SETFLOAT(&rlist[3], x_humoments.hu4);
+ SETFLOAT(&rlist[4], x_humoments.hu5);
+ SETFLOAT(&rlist[5], x_humoments.hu6);
+ SETFLOAT(&rlist[6], x_humoments.hu7);
+
+ outlet_list( m_dataout, 0, 7, rlist );
+}
+
+void pix_opencv_hu_moments :: processYUVImage(imageStruct &image)
+{
+ post( "pix_opencv_hu_moments : yuv format not supported" );
+}
+
+void pix_opencv_hu_moments :: processGrayImage(imageStruct &image)
+{
+ unsigned char *pixels = image.data;
+
+ if ((this->comp_xsize!=image.xsize)||(this->comp_ysize!=image.ysize)||(!rgb)) {
+
+ this->comp_xsize = image.xsize;
+ this->comp_ysize = image.ysize;
+
+ //Destroy cv_images to clean memory
+ if ( rgb )
+ {
+ cvReleaseImage(&rgba);
+ cvReleaseImage(&rgb);
+ cvReleaseImage(&gray);
+ }
+
+ //create the orig image with new size
+ rgba = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 4);
+ rgb = cvCreateImage(cvSize(image.xsize,image.ysize), IPL_DEPTH_8U, 3);
+ gray = cvCreateImage(cvSize(rgb->width,rgb->height), IPL_DEPTH_8U, 1);
+
+ }
+ memcpy( gray->imageData, image.data, image.xsize*image.ysize );
+
+ cvMoments( gray, &x_moments, x_binary );
+ cvGetHuMoments( &x_moments, &x_humoments );
+
+ SETFLOAT(&rlist[0], x_humoments.hu1);
+ SETFLOAT(&rlist[1], x_humoments.hu2);
+ SETFLOAT(&rlist[2], x_humoments.hu3);
+ SETFLOAT(&rlist[3], x_humoments.hu4);
+ SETFLOAT(&rlist[4], x_humoments.hu5);
+ SETFLOAT(&rlist[5], x_humoments.hu6);
+ SETFLOAT(&rlist[6], x_humoments.hu7);
+
+ outlet_list( m_dataout, 0, 7, rlist );
+}
+
+/////////////////////////////////////////////////////////
+// floatThreshMess
+//
+/////////////////////////////////////////////////////////
+void pix_opencv_hu_moments :: floatBinaryMess (float binary)
+{
+ if ( ((int)binary==1) || ((int)binary==0) ) x_binary = (int)binary;
+}
+
+/////////////////////////////////////////////////////////
+// static member function
+//
+/////////////////////////////////////////////////////////
+void pix_opencv_hu_moments :: obj_setupCallback(t_class *classPtr)
+{
+ class_addmethod(classPtr, (t_method)&pix_opencv_hu_moments::floatBinaryMessCallback,
+ gensym("binary"), A_FLOAT, A_NULL);
+}
+
+void pix_opencv_hu_moments :: floatBinaryMessCallback(void *data, t_floatarg binary)
+{
+ GetMyClass(data)->floatBinaryMess((float)binary);
+}
+
diff --git a/pix_opencv_hu_moments.h b/pix_opencv_hu_moments.h
new file mode 100755
index 0000000..20c031c
--- /dev/null
+++ b/pix_opencv_hu_moments.h
@@ -0,0 +1,86 @@
+/*-----------------------------------------------------------------
+LOG
+ GEM - Graphics Environment for Multimedia
+
+ Hu moments calculator object
+
+ 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_HU_MOMENTS_H_
+#define INCLUDE_PIX_OPENCV_HU_MOMENTS_H_
+
+#include "Base/GemPixObj.h"
+
+#ifndef _EiC
+#include "cv.h"
+#endif
+
+/*-----------------------------------------------------------------
+-------------------------------------------------------------------
+CLASS
+ pix_opencv_hu_moments
+
+ Hu moments calculator object
+
+KEYWORDS
+ pix
+
+DESCRIPTION
+
+-----------------------------------------------------------------*/
+class GEM_EXTERN pix_opencv_hu_moments : public GemPixObj
+{
+ CPPEXTERN_HEADER(pix_opencv_hu_moments, GemPixObj)
+
+ public:
+
+ //////////
+ // Constructor
+ pix_opencv_hu_moments();
+
+ protected:
+
+ //////////
+ // Destructor
+ virtual ~pix_opencv_hu_moments();
+
+ //////////
+ // Do the processing
+ virtual void processRGBAImage(imageStruct &image);
+ virtual void processRGBImage(imageStruct &image);
+ virtual void processYUVImage(imageStruct &image);
+ virtual void processGrayImage(imageStruct &image);
+
+ //////////
+ // Set the new edge threshold
+ void floatBinaryMess(float binary);
+
+ // to detect changes in the image size
+ int comp_xsize;
+ int comp_ysize;
+
+ int x_binary;
+ t_outlet *m_dataout;
+ t_atom rlist[7];
+
+ private:
+
+ //////////
+ // Static member functions
+ static void floatBinaryMessCallback(void *data, t_floatarg binary);
+
+ /////////
+ // IplImage needed
+ IplImage *rgba, *rgb, *gray;
+ CvMoments x_moments;
+ CvHuMoments x_humoments;
+};
+
+#endif // for header file