aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rwxr-xr-xpix_opencv_camshift-help.pd174
-rwxr-xr-xpix_opencv_camshift.cc450
-rwxr-xr-xpix_opencv_camshift.h109
4 files changed, 734 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 51b41a1..7209f6d 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_hist_compare.cc pix_opencv_knear.cc pix_opencv_threshold.cc pix_opencv_floodfill.cc pix_opencv_athreshold.cc pix_opencv_bgstats.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
all: $(SOURCES:.cc=.$(EXTENSION))
diff --git a/pix_opencv_camshift-help.pd b/pix_opencv_camshift-help.pd
new file mode 100755
index 0000000..1c65fa7
--- /dev/null
+++ b/pix_opencv_camshift-help.pd
@@ -0,0 +1,174 @@
+#N canvas 392 94 1192 685 10;
+#X obj 396 -37 gemhead;
+#X obj 218 457 pix_texture;
+#X obj 28 132 cnv 15 220 70 empty empty empty 20 12 0 14 -195568 -66577
+0;
+#N canvas 189 149 454 304 gemwin 0;
+#X obj 130 218 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 129 165 create \, 1;
+#X msg 205 166 destroy;
+#N canvas 87 154 363 340 Gem.init 0;
+#X obj 112 15 loadbang;
+#X msg 62 93 reset;
+#X obj 49 135 outlet;
+#X msg 107 89 dimen 320 240;
+#X msg 202 89 frame 15;
+#X obj 107 51 t b b b;
+#X connect 0 0 5 0;
+#X connect 1 0 2 0;
+#X connect 3 0 2 0;
+#X connect 4 0 2 0;
+#X connect 5 0 3 0;
+#X connect 5 1 4 0;
+#X connect 5 2 1 0;
+#X restore 289 80 pd Gem.init;
+#X obj 128 109 t b b b;
+#X msg 156 138 dimen 320 240;
+#X msg 251 138 frame 15;
+#X connect 2 0 3 0;
+#X connect 3 0 4 0;
+#X connect 3 0 9 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 9 0 6 0;
+#X connect 9 1 10 0;
+#X connect 9 2 11 0;
+#X connect 10 0 0 0;
+#X connect 11 0 0 0;
+#X restore 35 178 pd gemwin;
+#X msg 35 157 destroy;
+#X text 36 136 Create window and render;
+#X obj 340 181 cnv 15 600 350 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 1 1
+;
+#X obj 580 26 loadbang;
+#X msg 531 52 colorspace RGBA;
+#X obj 952 123 gemmouse;
+#X obj 1008 230 f;
+#X obj 978 229 f;
+#X obj 1022 201 t b b;
+#X obj 975 274 pack f f;
+#X obj 998 151 route 1;
+#X msg 1019 176 bang;
+#X floatatom 969 251 5 0 0 0 - - -;
+#X floatatom 1022 254 5 0 0 0 - - -;
+#X obj 208 534 rectangle 4 3;
+#X obj 212 489 pix_resize 320 240;
+#X obj 399 419 pix_opencv_camshift;
+#X obj 510 449 unpack f f f f f;
+#X floatatom 511 479 5 0 0 0 - - -;
+#X floatatom 550 479 5 0 0 0 - - -;
+#X floatatom 588 479 5 0 0 0 - - -;
+#X floatatom 627 479 5 0 0 0 - - -;
+#X floatatom 668 479 5 0 0 0 - - -;
+#X text 538 503 center Y;
+#X text 588 493 width;
+#X text 623 504 height;
+#X text 498 493 center X;
+#X text 666 495 angle;
+#X text 622 448 for the tracked object;
+#X msg 488 277 backproject \$1;
+#X text 607 278 show the backproject flow image;
+#X obj 585 278 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
+1;
+#X msg 446 194 vmin \$1;
+#X floatatom 502 196 5 0 0 0 - - -;
+#X floatatom 518 220 5 0 0 0 - - -;
+#X msg 464 220 vmax \$1;
+#X floatatom 531 251 5 0 0 0 - - -;
+#X msg 477 250 smin \$1;
+#X text 556 220 V pre-filtering maximal value ( default : 256 );
+#X text 570 249 S pre-filtering minimal value ( default : 30 );
+#X msg 520 357 track \$1 \$2;
+#X text 597 355 track %x %y : mark the object to track;
+#X floatatom 564 310 5 0 0 0 - - -;
+#X floatatom 581 334 5 0 0 0 - - -;
+#X msg 499 308 rwidth \$1;
+#X msg 508 332 rheight \$1;
+#X text 600 308 initial search region width ( default : 20 );
+#X text 619 333 initial search region height ( default : 20 );
+#X text 547 196 V pre-filtering minimal value ( default : 50 );
+#X text 34 40 pix_opencv_camshift : continuously adaptive mean-shift
+algorithm to track objects based on a hidden histogram of the hue component
+of pixels.;
+#X text 34 75 written by Yves Degoyon ( ydegoyon@gmail.com ) \, inspired
+by OpenCV samples code.;
+#X msg 740 52 colorspace RGB;
+#X msg 636 52 colorspace Grey;
+#X connect 0 0 16 0;
+#X connect 1 0 31 0;
+#X connect 3 0 4 0;
+#X connect 4 0 3 0;
+#X connect 7 0 14 0;
+#X connect 8 0 9 0;
+#X connect 8 1 10 0;
+#X connect 8 2 11 0;
+#X connect 12 0 13 0;
+#X connect 13 0 16 1;
+#X connect 14 0 15 0;
+#X connect 15 0 16 0;
+#X connect 16 0 32 0;
+#X connect 16 1 8 0;
+#X connect 16 2 12 0;
+#X connect 17 0 16 0;
+#X connect 18 0 17 0;
+#X connect 19 0 20 0;
+#X connect 20 0 16 0;
+#X connect 21 0 23 1;
+#X connect 21 1 22 1;
+#X connect 21 2 26 0;
+#X connect 22 0 25 1;
+#X connect 22 0 29 0;
+#X connect 23 0 25 0;
+#X connect 23 0 28 0;
+#X connect 24 0 23 0;
+#X connect 24 1 22 0;
+#X connect 25 0 56 0;
+#X connect 26 0 27 0;
+#X connect 27 0 24 0;
+#X connect 31 0 30 0;
+#X connect 32 0 1 0;
+#X connect 32 1 33 0;
+#X connect 33 0 34 0;
+#X connect 33 1 35 0;
+#X connect 33 2 36 0;
+#X connect 33 3 37 0;
+#X connect 33 4 38 0;
+#X connect 45 0 32 0;
+#X connect 47 0 45 0;
+#X connect 48 0 32 0;
+#X connect 49 0 48 0;
+#X connect 50 0 51 0;
+#X connect 51 0 32 0;
+#X connect 52 0 53 0;
+#X connect 53 0 32 0;
+#X connect 56 0 32 0;
+#X connect 58 0 60 0;
+#X connect 59 0 61 0;
+#X connect 60 0 32 0;
+#X connect 61 0 32 0;
+#X connect 67 0 16 0;
+#X connect 68 0 16 0;
diff --git a/pix_opencv_camshift.cc b/pix_opencv_camshift.cc
new file mode 100755
index 0000000..8703734
--- /dev/null
+++ b/pix_opencv_camshift.cc
@@ -0,0 +1,450 @@
+
+//
+// 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_camshift.h"
+#include <stdio.h>
+
+CPPEXTERN_NEW(pix_opencv_camshift)
+
+/////////////////////////////////////////////////////////
+//
+// pix_opencv_camshift
+//
+/////////////////////////////////////////////////////////
+// Constructor
+//
+/////////////////////////////////////////////////////////
+
+pix_opencv_camshift :: pix_opencv_camshift()
+{
+ int i;
+ int hdims = 16;
+ float hranges_arr[] = {0,180};
+ float* hranges = hranges_arr;
+
+ comp_xsize=320;
+ comp_ysize=240;
+
+ m_dataout = outlet_new(this->x_obj, &s_anything);
+
+ x_track = 0;
+ x_init = 0;
+ x_rwidth = 20;
+ x_rheight = 20;
+ x_backproject = 0;
+ x_vmin = 50;
+ x_vmax = 256;
+ x_smin = 30;
+
+ 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);
+ hsv = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 3);
+ hue = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ mask = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ backproject = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ hist = cvCreateHist( 1, &hdims, CV_HIST_ARRAY, &hranges, 1 );
+}
+
+/////////////////////////////////////////////////////////
+// Destructor
+//
+/////////////////////////////////////////////////////////
+pix_opencv_camshift :: ~pix_opencv_camshift()
+{
+ // Destroy cv_images
+ cvReleaseImage(&rgba);
+ cvReleaseImage(&rgb);
+ cvReleaseImage(&gray);
+ cvReleaseImage(&hsv);
+ cvReleaseImage(&hue);
+ cvReleaseImage(&mask);
+ cvReleaseImage(&backproject);
+ cvReleaseHist(&hist);
+}
+
+/////////////////////////////////////////////////////////
+// processImage
+//
+/////////////////////////////////////////////////////////
+void pix_opencv_camshift :: processRGBAImage(imageStruct &image)
+{
+ int i, k;
+ int im;
+ int marked;
+ int hdims = 16;
+ float hranges_arr[] = {0,180};
+ float* hranges = hranges_arr;
+
+
+ if ((this->comp_xsize!=image.xsize)&&(this->comp_ysize!=image.ysize))
+ {
+
+ this->comp_xsize=image.xsize;
+ this->comp_ysize=image.ysize;
+
+ cvReleaseImage(&rgba);
+ cvReleaseImage(&rgb);
+ cvReleaseImage(&gray);
+ cvReleaseImage(&hsv);
+ cvReleaseImage(&hue);
+ cvReleaseImage(&mask);
+ cvReleaseImage(&backproject);
+ cvReleaseHist(&hist);
+
+ 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);
+ hsv = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 3);
+ hue = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ mask = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ backproject = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ hist = cvCreateHist( 1, &hdims, CV_HIST_ARRAY, &hranges, 1 );
+
+ }
+
+ memcpy( rgba->imageData, image.data, image.xsize*image.ysize*4 );
+
+ // Convert to hsv
+ cvCvtColor(rgba, rgb, CV_BGRA2BGR);
+ cvCvtColor(rgb, hsv, CV_BGR2HSV);
+
+ if ( x_track )
+ {
+ cvInRangeS( hsv, cvScalar(0,x_smin,MIN(x_vmin,x_vmax),0), cvScalar(180,256,MAX(x_vmin,x_vmax),0), mask );
+ cvSplit( hsv, hue, 0, 0, 0 );
+
+ if ( x_init )
+ {
+ float max_val = 0.f;
+ x_init = 0;
+ cvSetImageROI( hue, selection );
+ cvSetImageROI( mask, selection );
+ cvCalcHist( &hue, hist, 0, mask );
+ cvGetMinMaxHistValue( hist, 0, &max_val, 0, 0 );
+ cvConvertScale( hist->bins, hist->bins, max_val ? 255. / max_val : 0., 0 );
+ cvResetImageROI( hue );
+ cvResetImageROI( mask );
+ trackwindow = selection;
+ }
+
+ cvCalcBackProject( (IplImage**)&(hue), (CvArr*)backproject, (const CvHistogram*)hist );
+ cvAnd( backproject, mask, backproject, 0 );
+ cvCamShift( backproject, trackwindow,
+ cvTermCriteria( CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 10, 1 ),
+ &trackcomp, &trackbox );
+ trackwindow = trackcomp.rect;
+
+ if( x_backproject )
+ cvCvtColor( backproject, rgb, CV_GRAY2BGR );
+ if( !rgb->origin )
+ trackbox.angle = -trackbox.angle;
+ cvEllipseBox( rgb, trackbox, CV_RGB(255,0,0), 3, CV_AA, 0 );
+ SETFLOAT(&x_list[0], trackbox.center.x);
+ SETFLOAT(&x_list[1], trackbox.center.y);
+ SETFLOAT(&x_list[2], trackbox.size.width);
+ SETFLOAT(&x_list[3], trackbox.size.height);
+ SETFLOAT(&x_list[4], trackbox.angle);
+ outlet_list( m_dataout, 0, 5, x_list );
+ }
+
+ cvCvtColor(rgb, rgba, CV_BGR2BGRA);
+ memcpy( image.data, rgba->imageData, image.xsize*image.ysize*4 );
+}
+
+void pix_opencv_camshift :: processRGBImage(imageStruct &image)
+{
+ int i, k;
+ int im;
+ int marked;
+ int hdims = 16;
+ float hranges_arr[] = {0,180};
+ float* hranges = hranges_arr;
+
+
+ if ((this->comp_xsize!=image.xsize)&&(this->comp_ysize!=image.ysize))
+ {
+
+ this->comp_xsize=image.xsize;
+ this->comp_ysize=image.ysize;
+
+ cvReleaseImage(&rgba);
+ cvReleaseImage(&rgb);
+ cvReleaseImage(&gray);
+ cvReleaseImage(&hsv);
+ cvReleaseImage(&hue);
+ cvReleaseImage(&mask);
+ cvReleaseImage(&backproject);
+ cvReleaseHist(&hist);
+
+ 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);
+ hsv = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 3);
+ hue = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ mask = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ backproject = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ hist = cvCreateHist( 1, &hdims, CV_HIST_ARRAY, &hranges, 1 );
+
+ }
+
+ memcpy( rgb->imageData, image.data, image.xsize*image.ysize*3 );
+
+ // Convert to hsv
+ cvCvtColor(rgb, hsv, CV_BGR2HSV);
+
+ if ( x_track )
+ {
+ cvInRangeS( hsv, cvScalar(0,x_smin,MIN(x_vmin,x_vmax),0), cvScalar(180,256,MAX(x_vmin,x_vmax),0), mask );
+ cvSplit( hsv, hue, 0, 0, 0 );
+
+ if ( x_init )
+ {
+ float max_val = 0.f;
+ x_init = 0;
+ cvSetImageROI( hue, selection );
+ cvSetImageROI( mask, selection );
+ cvCalcHist( &hue, hist, 0, mask );
+ cvGetMinMaxHistValue( hist, 0, &max_val, 0, 0 );
+ cvConvertScale( hist->bins, hist->bins, max_val ? 255. / max_val : 0., 0 );
+ cvResetImageROI( hue );
+ cvResetImageROI( mask );
+ trackwindow = selection;
+ }
+
+ cvCalcBackProject( (IplImage**)&(hue), (CvArr*)backproject, (const CvHistogram*)hist );
+ cvAnd( backproject, mask, backproject, 0 );
+ cvCamShift( backproject, trackwindow,
+ cvTermCriteria( CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 10, 1 ),
+ &trackcomp, &trackbox );
+ trackwindow = trackcomp.rect;
+
+ if( x_backproject )
+ cvCvtColor( backproject, rgb, CV_GRAY2BGR );
+ if( !rgb->origin )
+ trackbox.angle = -trackbox.angle;
+ cvEllipseBox( rgb, trackbox, CV_RGB(255,0,0), 3, CV_AA, 0 );
+ SETFLOAT(&x_list[0], trackbox.center.x);
+ SETFLOAT(&x_list[1], trackbox.center.y);
+ SETFLOAT(&x_list[2], trackbox.size.width);
+ SETFLOAT(&x_list[3], trackbox.size.height);
+ SETFLOAT(&x_list[4], trackbox.angle);
+ outlet_list( m_dataout, 0, 5, x_list );
+ }
+
+ memcpy( image.data, rgb->imageData, image.xsize*image.ysize*3 );
+}
+
+void pix_opencv_camshift :: processYUVImage(imageStruct &image)
+{
+ post( "pix_opencv_camshift : yuv format not supported" );
+}
+
+void pix_opencv_camshift :: processGrayImage(imageStruct &image)
+{
+ int i, k;
+ int im;
+ int marked;
+ int hdims = 16;
+ float hranges_arr[] = {0,180};
+ float* hranges = hranges_arr;
+
+
+ if ((this->comp_xsize!=image.xsize)&&(this->comp_ysize!=image.ysize))
+ {
+
+ this->comp_xsize=image.xsize;
+ this->comp_ysize=image.ysize;
+
+ cvReleaseImage(&rgba);
+ cvReleaseImage(&rgb);
+ cvReleaseImage(&gray);
+ cvReleaseImage(&hsv);
+ cvReleaseImage(&hue);
+ cvReleaseImage(&mask);
+ cvReleaseImage(&backproject);
+ cvReleaseHist(&hist);
+
+ 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);
+ hsv = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 3);
+ hue = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ mask = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ backproject = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1);
+ hist = cvCreateHist( 1, &hdims, CV_HIST_ARRAY, &hranges, 1 );
+
+ }
+
+ memcpy( gray->imageData, image.data, image.xsize*image.ysize );
+
+ // Convert to hsv
+ cvCvtColor(gray, rgb, CV_GRAY2BGR);
+ cvCvtColor(rgb, hsv, CV_BGR2HSV);
+
+ if ( x_track )
+ {
+ cvInRangeS( hsv, cvScalar(0,x_smin,MIN(x_vmin,x_vmax),0), cvScalar(180,256,MAX(x_vmin,x_vmax),0), mask );
+ cvSplit( hsv, hue, 0, 0, 0 );
+
+ if ( x_init )
+ {
+ float max_val = 0.f;
+ x_init = 0;
+ cvSetImageROI( hue, selection );
+ cvSetImageROI( mask, selection );
+ cvCalcHist( &hue, hist, 0, mask );
+ cvGetMinMaxHistValue( hist, 0, &max_val, 0, 0 );
+ cvConvertScale( hist->bins, hist->bins, max_val ? 255. / max_val : 0., 0 );
+ cvResetImageROI( hue );
+ cvResetImageROI( mask );
+ trackwindow = selection;
+ }
+
+ cvCalcBackProject( (IplImage**)&(hue), (CvArr*)backproject, (const CvHistogram*)hist );
+ cvAnd( backproject, mask, backproject, 0 );
+ cvCamShift( backproject, trackwindow,
+ cvTermCriteria( CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 10, 1 ),
+ &trackcomp, &trackbox );
+ trackwindow = trackcomp.rect;
+
+ if( x_backproject )
+ memcpy( gray->imageData, backproject->imageData, image.xsize*image.ysize );
+ if( !rgb->origin )
+ trackbox.angle = -trackbox.angle;
+ cvEllipseBox( gray, trackbox, CV_RGB(255,0,0), 3, CV_AA, 0 );
+ SETFLOAT(&x_list[0], trackbox.center.x);
+ SETFLOAT(&x_list[1], trackbox.center.y);
+ SETFLOAT(&x_list[2], trackbox.size.width);
+ SETFLOAT(&x_list[3], trackbox.size.height);
+ SETFLOAT(&x_list[4], trackbox.angle);
+ outlet_list( m_dataout, 0, 5, x_list );
+ }
+
+ memcpy( image.data, gray->imageData, image.xsize*image.ysize );
+}
+
+/////////////////////////////////////////////////////////
+// static member function
+//
+/////////////////////////////////////////////////////////
+
+void pix_opencv_camshift :: obj_setupCallback(t_class *classPtr)
+{
+ class_addmethod(classPtr, (t_method)&pix_opencv_camshift::backProjectMessCallback,
+ gensym("backproject"), A_FLOAT, A_NULL);
+ class_addmethod(classPtr, (t_method)&pix_opencv_camshift::vMinMessCallback,
+ gensym("vmin"), A_FLOAT, A_NULL);
+ class_addmethod(classPtr, (t_method)&pix_opencv_camshift::vMaxMessCallback,
+ gensym("vmax"), A_FLOAT, A_NULL);
+ class_addmethod(classPtr, (t_method)&pix_opencv_camshift::sMinMessCallback,
+ gensym("smin"), A_NULL);
+ class_addmethod(classPtr, (t_method)&pix_opencv_camshift::trackMessCallback,
+ gensym("track"), A_FLOAT, A_FLOAT, A_NULL);
+ class_addmethod(classPtr, (t_method)&pix_opencv_camshift::rWidthMessCallback,
+ gensym("rwidth"), A_FLOAT, A_NULL);
+ class_addmethod(classPtr, (t_method)&pix_opencv_camshift::rHeightMessCallback,
+ gensym("rheight"), A_NULL);
+}
+
+void pix_opencv_camshift :: backProjectMessCallback(void *data, t_floatarg backproject)
+{
+ GetMyClass(data)->backProjectMess((float)backproject);
+}
+
+void pix_opencv_camshift :: vMinMessCallback(void *data, t_floatarg vmin)
+{
+ GetMyClass(data)->vMinMess((float)vmin);
+}
+
+void pix_opencv_camshift :: vMaxMessCallback(void *data, t_floatarg vmax)
+{
+ GetMyClass(data)->vMaxMess((float)vmax);
+}
+
+void pix_opencv_camshift :: sMinMessCallback(void *data, t_floatarg smin)
+{
+ GetMyClass(data)->sMinMess((float)smin);
+}
+
+void pix_opencv_camshift :: trackMessCallback(void *data, t_floatarg px, t_floatarg py)
+{
+ GetMyClass(data)->trackMess((float)px, (float)py);
+}
+
+void pix_opencv_camshift :: rWidthMessCallback(void *data, t_floatarg rwidth)
+{
+ GetMyClass(data)->rWidthMess((float)rwidth);
+}
+
+void pix_opencv_camshift :: rHeightMessCallback(void *data, t_floatarg rheight)
+{
+ GetMyClass(data)->rHeightMess((float)rheight);
+}
+
+void pix_opencv_camshift :: backProjectMess(float backproject)
+{
+ if ( ( (int)backproject==0 ) || ( (int)backproject==1 ) ) x_backproject = (int)backproject;
+}
+
+void pix_opencv_camshift :: vMinMess(float vmin)
+{
+ if ( ( (int)vmin>=0 ) || ( (int)vmin<256 ) ) x_vmin = (int)vmin;
+}
+
+void pix_opencv_camshift :: vMaxMess(float vmax)
+{
+ if ( ( (int)vmax>=0 ) || ( (int)vmax<256 ) ) x_vmax = (int)vmax;
+}
+
+void pix_opencv_camshift :: sMinMess(float smin)
+{
+ if ( ( (int)smin>=0 ) || ( (int)smin<256 ) ) x_smin = (int)smin;
+}
+
+void pix_opencv_camshift :: trackMess(float px, float py)
+{
+ int rx, ry, w, h;
+
+ if ( ( px<0.0 ) || ( px>comp_xsize ) || ( py<0.0 ) || ( py>comp_ysize ) ) return;
+
+ py = comp_ysize - py;
+ origin = cvPoint((int)px,(int)py);
+ rx = ( (int)px-(x_rwidth/2) < 0 )? 0:(int)px-(x_rwidth/2);
+ ry = ( (int)py-(x_rheight/2) < 0 )? 0:(int)py-(x_rheight/2);
+ w = (rx+x_rwidth>comp_xsize ) ? ( comp_xsize - rx ):x_rwidth;
+ h = (ry+x_rheight>comp_ysize ) ? ( comp_ysize - ry ):x_rheight;
+ selection = cvRect(rx,ry,w,h);
+ post( "pix_opencv_camshift : track point (%f,%f) region (%d %d %d %d)", px, py, rx, ry, w, h );
+ x_track = 1;
+ x_init = 1;
+}
+
+void pix_opencv_camshift :: rWidthMess(float rwidth)
+{
+ if ( (int)rwidth>=0 ) x_rwidth = (int)rwidth;
+ // refresh selection zone
+ trackMess( (float)origin.x, (float)origin.y );
+}
+
+void pix_opencv_camshift :: rHeightMess(float rheight)
+{
+ if ( (int)rheight>=0 ) x_rheight = (int)rheight;
+ // refresh selection zone
+ trackMess( (float)origin.x, (float)origin.y );
+}
+
diff --git a/pix_opencv_camshift.h b/pix_opencv_camshift.h
new file mode 100755
index 0000000..6dd4a83
--- /dev/null
+++ b/pix_opencv_camshift.h
@@ -0,0 +1,109 @@
+/*-----------------------------------------------------------------
+LOG
+ GEM - Graphics Environment for Multimedia
+
+ Continously adaptive mean-shift tracker
+
+ 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_LK_H_
+#define INCLUDE_PIX_OPENCV_LK_H_
+
+#include "Base/GemPixObj.h"
+
+#ifndef _EiC
+#include "cv.h"
+#endif
+
+#define MAX_MARKERS 500
+const int MAX_COUNT = 500;
+
+/*-----------------------------------------------------------------
+-------------------------------------------------------------------
+CLASS
+ pix_opencv_camshift
+
+ Change pix to greyscale
+
+KEYWORDS
+ pix
+
+DESCRIPTION
+
+-----------------------------------------------------------------*/
+class GEM_EXTERN pix_opencv_camshift : public GemPixObj
+{
+ CPPEXTERN_HEADER(pix_opencv_camshift, GemPixObj)
+
+ public:
+
+ //////////
+ // Constructor
+ pix_opencv_camshift();
+
+ protected:
+
+ //////////
+ // Destructor
+ virtual ~pix_opencv_camshift();
+
+ //////////
+ // Do the processing
+ virtual void processRGBAImage(imageStruct &image);
+ virtual void processRGBImage(imageStruct &image);
+ virtual void processYUVImage(imageStruct &image);
+ virtual void processGrayImage(imageStruct &image);
+
+ void backProjectMess(float backproject);
+ void vMinMess(float vmin);
+ void vMaxMess(float vmax);
+ void sMinMess(float smin);
+ void trackMess(float px, float py);
+ void rWidthMess(float rwidth);
+ void rHeightMess(float rheight);
+
+ int comp_xsize;
+ int comp_ysize;
+
+ t_outlet *m_dataout;
+ int x_track;
+ int x_init;
+ int x_rwidth;
+ int x_rheight;
+ int x_backproject;
+ int x_vmin;
+ int x_vmax;
+ int x_smin;
+
+ private:
+
+ //////////
+ // Static member functions
+ static void backProjectMessCallback(void *data, float backproject);
+ static void vMinMessCallback(void *data, float vmin);
+ static void vMaxMessCallback(void *data, float vmax);
+ static void sMinMessCallback(void *data, float smin);
+ static void trackMessCallback(void *data, float px, float py);
+ static void rWidthMessCallback(void *data, float rwidth);
+ static void rHeightMessCallback(void *data, float rheight);
+
+ // Internal Open CV data
+ IplImage *rgba, *rgb, *gray, *hsv, *hue, *mask, *backproject;
+ CvHistogram *hist;
+ CvPoint origin;
+ CvRect selection;
+ CvRect trackwindow;
+ CvBox2D trackbox;
+ CvConnectedComp trackcomp;
+
+ t_atom x_list[5];
+};
+
+#endif // for header file