aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--TODO5
-rw-r--r--pdp_opencv_lk-help.pd131
-rw-r--r--pdp_opencv_lk.c114
-rw-r--r--pdp_opencv_surf-help.pd136
-rw-r--r--pdp_opencv_surf.cc690
6 files changed, 989 insertions, 89 deletions
diff --git a/Makefile b/Makefile
index 6bad1b5..46fbdd7 100644
--- a/Makefile
+++ b/Makefile
@@ -37,7 +37,7 @@ endif
.SUFFIXES = $(EXTENSION)
-SOURCES = pdp_opencv_threshold.c pdp_opencv_edge.c pdp_opencv_distrans.c pdp_opencv_laplace.c pdp_opencv_motempl.c pdp_opencv_morphology.c pdp_opencv_haarcascade.c pdp_opencv_contours_convexity.c pdp_opencv_contours_boundingrect.c pdp_opencv_bgsubstract.c pdp_opencv_lk.c pdp_opencv_floodfill.c pdp_opencv_hist_compare.c pdp_opencv_dft.c pdp_opencv_knear.cc pdp_opencv_hu_moments.c pdp_opencv_hu_compare.cc pdp_opencv_pgh_compare.cc pdp_opencv_bgstats.cc
+SOURCES = pdp_opencv_threshold.c pdp_opencv_edge.c pdp_opencv_distrans.c pdp_opencv_laplace.c pdp_opencv_motempl.c pdp_opencv_morphology.c pdp_opencv_haarcascade.c pdp_opencv_contours_convexity.c pdp_opencv_contours_boundingrect.c pdp_opencv_bgsubstract.c pdp_opencv_lk.c pdp_opencv_floodfill.c pdp_opencv_hist_compare.c pdp_opencv_dft.c pdp_opencv_knear.cc pdp_opencv_hu_moments.c pdp_opencv_hu_compare.cc pdp_opencv_pgh_compare.cc pdp_opencv_bgstats.cc pdp_opencv_surf.cc
all: $(SOURCES:.c=.$(EXTENSION)) $(SOURCES:.cc=.$(EXTENSION))
diff --git a/TODO b/TODO
index ab6af8c..c66f708 100644
--- a/TODO
+++ b/TODO
@@ -154,9 +154,8 @@ simple edge ... http://www.hci.iastate.edu/575x/doku.php?id=code_samples:edge_de
http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html#SECTION00053000000000000000
############################# sevy ++
+SURF ( remarkable points )
adaptive threshold
hough lines/circles
-SIFT ( remarkable points )
-SURF ( remarkable points )
camshift ( very greedy )
-stereo calibration ( need two cams and a chessboard )
+one day : stereo calibration ( need two cams and a chessboard )
diff --git a/pdp_opencv_lk-help.pd b/pdp_opencv_lk-help.pd
index 2140c92..f7c2ea2 100644
--- a/pdp_opencv_lk-help.pd
+++ b/pdp_opencv_lk-help.pd
@@ -1,4 +1,4 @@
-#N canvas 350 49 833 785 10;
+#N canvas 493 49 833 785 10;
#X text -16 -86 written by Lluis Gomez i Bigorda ( lluisgomez@hangar.org
) and Yves Degoyon ( ydegoyon@gmail.com );
#X obj -17 -55 cnv 15 621 250 empty empty empty 20 12 0 14 -260097
@@ -33,65 +33,74 @@
#X text 253 -17 Camera input;
#X obj 73 161 hsl 128 15 0 500 0 0 empty empty empty -2 -8 0 10 -262144
-1 -1 0 1;
-#X obj -15 203 cnv 15 621 400 empty empty empty 20 12 0 14 -258113
+#X obj -15 203 cnv 15 621 430 empty empty empty 20 12 0 14 -258113
-66577 0;
-#X obj 15 621 pdp_xv;
-#X floatatom 108 313 5 0 0 0 - - -;
-#X obj 14 497 pdp_opencv_lk;
-#X text 143 312 window size;
-#X obj 185 292 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 1
+#X obj 14 642 pdp_xv;
+#X floatatom 64 285 5 0 0 0 - - -;
+#X obj 16 546 pdp_opencv_lk;
+#X text 99 284 window size;
+#X obj 163 306 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
1;
-#X msg 100 290 nightmode \$1;
-#X text 204 293 set nightmode;
-#X msg 95 264 quality \$1;
-#X floatatom 170 265 5 0 0 0 - - -;
-#X floatatom 178 240 5 0 0 0 - - -;
-#X msg 81 239 mindistance \$1;
-#X text 219 238 set distance ( default 10 );
-#X msg 74 211 init;
+#X msg 78 304 nightmode \$1;
+#X text 182 307 set nightmode;
+#X msg 57 264 quality \$1;
+#X floatatom 132 265 5 0 0 0 - - -;
+#X floatatom 140 240 5 0 0 0 - - -;
+#X msg 43 239 mindistance \$1;
+#X text 181 238 set distance ( default 10 );
+#X msg 30 213 init;
#X obj 414 169 pdp_xv;
#X obj 314 169 pdp_opencv_edge;
-#X floatatom 263 265 5 0 0 0 - - -;
-#X obj 111 211 t b;
-#X obj 208 263 / 1000;
-#X msg 66 621 cursor 1;
-#X obj 15 647 route press;
-#X msg 109 339 mark \$1 \$2;
-#X msg 116 366 delete \$1;
-#X text 307 366 delete a marker;
-#X msg 116 391 clear;
-#X text 164 392 delete all markers;
-#X msg 115 414 maxmove \$1;
-#X text 229 414 max movement of a marker ( default 5 pisels );
-#X floatatom 191 416 5 0 0 0 - - -;
-#X text 395 264 set quality ( default 100 );
-#X msg 303 263 100;
-#X obj 336 263 loadbang;
-#X text 188 340 mark %x %y : mark a point to track ( max points : 10
+#X floatatom 225 265 5 0 0 0 - - -;
+#X obj 67 213 t b;
+#X obj 170 263 / 1000;
+#X msg 65 642 cursor 1;
+#X obj 14 668 route press;
+#X msg 101 367 mark \$1 \$2;
+#X msg 106 391 delete \$1;
+#X text 301 389 delete a marker;
+#X msg 109 413 clear;
+#X text 157 414 delete all markers;
+#X msg 119 435 maxmove \$1;
+#X floatatom 195 437 5 0 0 0 - - -;
+#X text 357 264 set quality ( default 100 );
+#X msg 265 263 100;
+#X obj 298 263 loadbang;
+#X text 180 368 mark %x %y : mark a point to track ( max points : 10
);
-#X obj 112 546 unpack f f;
-#X floatatom 113 571 5 0 0 0 - - -;
-#X floatatom 171 572 5 0 0 0 - - -;
-#X text 114 587 X;
-#X text 169 588 Y;
-#X obj 112 525 route 1 2 3 4 5 6 7 8 9 10;
+#X obj 117 588 unpack f f;
+#X floatatom 116 606 5 0 0 0 - - -;
+#X floatatom 174 607 5 0 0 0 - - -;
+#X text 118 618 X;
+#X text 173 617 Y;
+#X obj 117 568 route 1 2 3 4 5 6 7 8 9 10;
#X obj 285 169 / 2;
-#X text 144 623 <-- mark the points you want to track in the video
+#X text 143 644 <-- mark the points you want to track in the video
window;
-#X text 280 527 position of each marked point;
-#X text 197 442 make a delaunay with all points;
-#X msg 116 440 delaunay on;
-#X msg 118 461 delaunay off;
-#X text 228 472 make a delaunay with point 1 and a tolerance of 50
+#X text 286 567 position of each marked point;
+#X text 207 482 make a delaunay with all points;
+#X msg 127 482 delaunay on;
+#X msg 135 502 delaunay off;
+#X text 231 517 make a delaunay with point 1 and a tolerance of 50
( all points which color is in that range will be included in the delaunay)
;
-#X obj 181 366 hradio 15 1 0 8 empty empty empty 0 -8 0 10 -262144
+#X obj 171 391 hradio 15 1 0 8 empty empty empty 0 -8 0 10 -262144
-1 -1 0;
-#X msg 124 484 pdelaunay 1 50;
+#X msg 137 527 pdelaunay 1 50;
#X text -14 -111 pdp_opencv_lk : Lukas-Kanade corner points tracking
;
#X text -14 -99 Corner points detection based on Shi and Tomasi;
-#X text 142 211 init corner points detections;
+#X text 98 213 init corner points detections;
+#X text 377 241 Detection parameters;
+#X msg 87 324 mark all;
+#X msg 97 345 mark none;
+#X text 150 325 mark all points;
+#X text 167 346 reset all markers;
+#X msg 118 458 ftolerance \$1;
+#X floatatom 210 458 5 0 0 0 - - -;
+#X text 232 437 max movement of a marker ( default 8 pisels );
+#X text 250 458 frame tolerance for point identification ( default
+: 5 );
#X connect 2 0 3 0;
#X connect 3 0 5 0;
#X connect 4 0 5 0;
@@ -123,7 +132,7 @@ window;
#X connect 29 0 30 1;
#X connect 30 0 28 0;
#X connect 30 0 46 0;
-#X connect 30 1 65 0;
+#X connect 30 1 64 0;
#X connect 32 0 33 0;
#X connect 33 0 30 0;
#X connect 35 0 30 0;
@@ -134,7 +143,7 @@ window;
#X connect 42 0 41 0;
#X connect 43 0 45 0;
#X connect 43 0 44 0;
-#X connect 43 0 66 0;
+#X connect 43 0 65 0;
#X connect 44 0 40 0;
#X connect 45 0 36 0;
#X connect 46 0 28 0;
@@ -143,14 +152,18 @@ window;
#X connect 49 0 30 0;
#X connect 51 0 30 0;
#X connect 53 0 30 0;
-#X connect 55 0 53 0;
-#X connect 57 0 43 0;
-#X connect 58 0 57 0;
-#X connect 60 0 61 0;
-#X connect 60 1 62 0;
-#X connect 65 0 60 0;
-#X connect 66 0 42 1;
+#X connect 54 0 53 0;
+#X connect 56 0 43 0;
+#X connect 57 0 56 0;
+#X connect 59 0 60 0;
+#X connect 59 1 61 0;
+#X connect 64 0 59 0;
+#X connect 65 0 42 1;
+#X connect 69 0 30 0;
#X connect 70 0 30 0;
-#X connect 71 0 30 0;
-#X connect 73 0 49 0;
-#X connect 74 0 30 0;
+#X connect 72 0 49 0;
+#X connect 73 0 30 0;
+#X connect 78 0 30 0;
+#X connect 79 0 30 0;
+#X connect 82 0 30 0;
+#X connect 83 0 82 0;
diff --git a/pdp_opencv_lk.c b/pdp_opencv_lk.c
index 5df5b05..915de71 100644
--- a/pdp_opencv_lk.c
+++ b/pdp_opencv_lk.c
@@ -32,8 +32,7 @@
#include "cv.h"
#endif
-#define MAX_MARKERS 10
-
+#define MAX_MARKERS 500
const int MAX_COUNT = 500;
typedef struct pdp_opencv_lk_struct
@@ -58,6 +57,8 @@ typedef struct pdp_opencv_lk_struct
double quality;
int min_distance;
int x_maxmove;
+ int x_ftolerance;
+ int x_markall;
int x_delaunay;
int x_threshold;
int x_xmark[MAX_MARKERS];
@@ -84,6 +85,8 @@ typedef struct pdp_opencv_lk_struct
} t_pdp_opencv_lk;
+static void pdp_opencv_lk_clear(t_pdp_opencv_lk *x);
+
static void pdp_opencv_lk_process_rgb(t_pdp_opencv_lk *x)
{
t_pdp *header = pdp_packet_header(x->x_packet0);
@@ -91,6 +94,7 @@ static void pdp_opencv_lk_process_rgb(t_pdp_opencv_lk *x)
t_pdp *newheader = pdp_packet_header(x->x_packet1);
short int *newdata = (short int *)pdp_packet_data(x->x_packet1);
int i,j,k,im;
+ int marked;
if ((x->x_width != (t_int)header->info.image.width) ||
(x->x_height != (t_int)header->info.image.height) || (!x->image))
@@ -138,7 +142,7 @@ static void pdp_opencv_lk_process_rgb(t_pdp_opencv_lk *x)
for ( im=0; im<MAX_MARKERS; im++ )
{
- x->x_found[im] = 0;
+ x->x_found[im]--;
}
if ( x->x_delaunay >= 0 )
@@ -242,9 +246,10 @@ static void pdp_opencv_lk_process_rgb(t_pdp_opencv_lk *x)
cvCircle( x->image, cvPointFrom32f(x->points[1][i]), 3, CV_RGB(0,255,0), -1, 8,0);
+ marked=0;
for ( im=0; im<MAX_MARKERS; im++ )
{
- // first marking
+ // search for this point
if ( x->x_xmark[im] != -1.0 )
{
if ( ( abs( x->points[1][i].x - x->x_xmark[im] ) <= x->x_maxmove ) && ( abs( x->points[1][i].y - x->x_ymark[im] ) <= x->x_maxmove ) )
@@ -254,7 +259,8 @@ static void pdp_opencv_lk_process_rgb(t_pdp_opencv_lk *x)
cvPutText( x->image, tindex, cvPointFrom32f(x->points[1][i]), &x->font, CV_RGB(255,255,255));
x->x_xmark[im]=x->points[1][i].x;
x->x_ymark[im]=x->points[1][i].y;
- x->x_found[im]=1;
+ x->x_found[im]++;
+ marked=1;
SETFLOAT(&x->x_list[0], im+1);
SETFLOAT(&x->x_list[1], x->x_xmark[im]);
SETFLOAT(&x->x_list[2], x->x_ymark[im]);
@@ -263,6 +269,19 @@ static void pdp_opencv_lk_process_rgb(t_pdp_opencv_lk *x)
}
}
+ if ( x->x_markall && !marked )
+ {
+ for ( im=0; im<MAX_MARKERS; im++)
+ {
+ if ( x->x_xmark[im] == -1 )
+ {
+ x->x_xmark[im]=x->points[1][i].x;
+ x->x_ymark[im]=x->points[1][i].y;
+ x->x_found[im]=x->x_ftolerance;
+ break;
+ }
+ }
+ }
}
x->count = k;
}
@@ -343,6 +362,7 @@ static void pdp_opencv_lk_process_rgb(t_pdp_opencv_lk *x)
{
if ( (x->x_xmark[im] != -1.0 ) && !x->x_found[im] )
{
+ // lost the point
x->x_xmark[im]=-1.0;
x->x_ymark[im]=-1.0;
SETFLOAT(&x->x_list[0], im+1);
@@ -395,6 +415,11 @@ static void pdp_opencv_lk_maxmove(t_pdp_opencv_lk *x, t_floatarg f)
if (f>=3.0) x->x_maxmove = (int)f;
}
+static void pdp_opencv_lk_ftolerance(t_pdp_opencv_lk *x, t_floatarg f)
+{
+ if (f>0.0) x->x_ftolerance = (int)f;
+}
+
static void pdp_opencv_lk_delaunay(t_pdp_opencv_lk *x, t_symbol *s)
{
if (s == gensym("on"))
@@ -417,34 +442,68 @@ static void pdp_opencv_lk_init(t_pdp_opencv_lk *x)
x->need_to_init = 1;
}
-static void pdp_opencv_lk_mark(t_pdp_opencv_lk *x, t_floatarg fperx, t_floatarg fpery )
+static void pdp_opencv_lk_mark(t_pdp_opencv_lk *x, t_symbol *s, int argc, t_atom *argv)
{
int i;
int inserted;
int px,py;
-
- if ( ( fperx < 0.0 ) || ( fperx > 1.0 ) || ( fpery < 0.0 ) || ( fpery > 1.0 ) )
- {
- return;
- }
- px = (int)(fperx*x->x_width);
- py = (int)(fpery*x->x_height);
- inserted = 0;
- for ( i=0; i<MAX_MARKERS; i++)
+ if ( argc == 1 ) // mark all
{
- if ( x->x_xmark[i] == -1 )
- {
- x->x_xmark[i] = px;
- x->x_ymark[i] = py;
- inserted = 1;
- break;
- }
+ if ( argv[0].a_type != A_SYMBOL )
+ {
+ error( "pdp_opencv_lk : wrong argument (should be 'all')" );
+ return;
+ }
+ if ( !strcmp( argv[0].a_w.w_symbol->s_name, "all" ) )
+ {
+ x->x_markall = 1;
+ return;
+ }
+ if ( !strcmp( argv[0].a_w.w_symbol->s_name, "none" ) )
+ {
+ x->x_markall = 0;
+ pdp_opencv_lk_clear(x);
+ return;
+ }
}
- if ( !inserted )
+ else
{
- post( "pdp_opencv_lk : max markers reached" );
- }
+ if ( ( argv[0].a_type != A_FLOAT ) || ( argv[1].a_type != A_FLOAT ) )
+ {
+ error( "pdp_opencv_lk : wrong argument (should be mark px py)" );
+ return;
+ }
+ else
+ {
+ float fperx = argv[0].a_w.w_float;
+ float fpery = argv[1].a_w.w_float;
+
+ if ( ( fperx < 0.0 ) || ( fperx > 1.0 ) || ( fpery < 0.0 ) || ( fpery > 1.0 ) )
+ {
+ return;
+ }
+
+ px = (int)(fperx*x->x_width);
+ py = (int)(fpery*x->x_height);
+ inserted = 0;
+ for ( i=0; i<MAX_MARKERS; i++)
+ {
+ if ( x->x_xmark[i] == -1 )
+ {
+ x->x_xmark[i] = px;
+ x->x_ymark[i] = py;
+ x->x_found[i] = x->x_ftolerance;
+ inserted = 1;
+ break;
+ }
+ }
+ if ( !inserted )
+ {
+ post( "pdp_opencv_lk : max markers reached" );
+ }
+ }
+ }
}
static void pdp_opencv_lk_delete(t_pdp_opencv_lk *x, t_floatarg findex )
@@ -579,9 +638,11 @@ void *pdp_opencv_lk_new(t_floatarg f)
x->quality = 0.1;
x->min_distance = 10;
x->x_maxmove = 8;
+ x->x_ftolerance = 8;
x->x_delaunay = -1;
x->x_threshold = -1;
+ x->x_markall = 0;
for ( i=0; i<MAX_MARKERS; i++ )
{
x->x_xmark[i] = -1;
@@ -623,11 +684,12 @@ void pdp_opencv_lk_setup(void)
class_addmethod(pdp_opencv_lk_class, (t_method)pdp_opencv_lk_nightmode, gensym("nightmode"), A_FLOAT, A_NULL );
class_addmethod(pdp_opencv_lk_class, (t_method)pdp_opencv_lk_quality, gensym("quality"), A_FLOAT, A_NULL );
class_addmethod(pdp_opencv_lk_class, (t_method)pdp_opencv_lk_init, gensym("init"), A_NULL );
- class_addmethod(pdp_opencv_lk_class, (t_method)pdp_opencv_lk_mark, gensym("mark"), A_FLOAT, A_FLOAT, A_NULL );
+ class_addmethod(pdp_opencv_lk_class, (t_method)pdp_opencv_lk_mark, gensym("mark"), A_GIMME, A_NULL );
class_addmethod(pdp_opencv_lk_class, (t_method)pdp_opencv_lk_delete, gensym("delete"), A_FLOAT, A_NULL );
class_addmethod(pdp_opencv_lk_class, (t_method)pdp_opencv_lk_clear, gensym("clear"), A_NULL );
class_addmethod(pdp_opencv_lk_class, (t_method)pdp_opencv_lk_mindistance, gensym("mindistance"), A_FLOAT, A_NULL );
class_addmethod(pdp_opencv_lk_class, (t_method)pdp_opencv_lk_maxmove, gensym("maxmove"), A_FLOAT, A_NULL );
+ class_addmethod(pdp_opencv_lk_class, (t_method)pdp_opencv_lk_ftolerance, gensym("ftolerance"), A_FLOAT, A_NULL );
class_addmethod(pdp_opencv_lk_class, (t_method)pdp_opencv_lk_delaunay, gensym("delaunay"), A_SYMBOL, A_NULL );
class_addmethod(pdp_opencv_lk_class, (t_method)pdp_opencv_lk_pdelaunay, gensym("pdelaunay"), A_FLOAT, A_FLOAT, A_NULL );
diff --git a/pdp_opencv_surf-help.pd b/pdp_opencv_surf-help.pd
new file mode 100644
index 0000000..d19f419
--- /dev/null
+++ b/pdp_opencv_surf-help.pd
@@ -0,0 +1,136 @@
+#N canvas 10 49 833 785 10;
+#X text -6 -88 written by Lluis Gomez i Bigorda ( lluisgomez@hangar.org
+) and Yves Degoyon ( ydegoyon@gmail.com );
+#X obj -17 -55 cnv 15 621 250 empty empty empty 20 12 0 14 -260097
+-66577 0;
+#X obj 223 -15 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
+1;
+#X obj 223 12 metro 40;
+#X msg 313 39 close;
+#X obj 243 110 pdp_v4l;
+#X msg 300 7 open /dev/video0;
+#X obj 412 -20 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 1
+1;
+#X obj 412 7 metro 40;
+#X msg 493 26 close;
+#X msg 489 2 open /dev/video0;
+#X obj 433 106 pdp_v4l2;
+#X msg 498 81 format \$1;
+#X obj 499 59 hradio 15 1 0 4 empty empty empty 0 -8 0 10 -262144 -1
+-1 0;
+#X obj 13 160 pdp_qt;
+#X obj 46 96 metro 40;
+#X msg 46 68 bang;
+#X msg 87 68 stop;
+#X obj 13 -1 openpanel;
+#X msg 13 24 open \$1;
+#X msg 13 -29 bang;
+#X msg 47 123 loop \$1;
+#X obj 127 123 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 1
+1;
+#X obj 127 41 loadbang;
+#X text 56 -26 playing a video file;
+#X text 253 -17 Camera input;
+#X obj 73 161 hsl 128 15 0 500 0 0 empty empty empty -2 -8 0 10 -262144
+-1 -1 0 1;
+#X obj -15 203 cnv 15 621 400 empty empty empty 20 12 0 14 -258113
+-66577 0;
+#X obj 15 621 pdp_xv;
+#X obj 135 237 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
+1;
+#X msg 50 238 nightmode \$1;
+#X text 154 241 set nightmode;
+#X msg 66 621 cursor 1;
+#X obj 15 647 route press;
+#X msg 97 301 mark \$1 \$2;
+#X msg 103 324 delete \$1;
+#X text 296 325 delete a marker;
+#X msg 114 347 clear;
+#X text 162 348 delete all markers;
+#X msg 129 377 maxmove \$1;
+#X text 243 377 max movement of a marker ( default 5 pisels );
+#X floatatom 205 379 5 0 0 0 - - -;
+#X text 170 301 mark %x %y : mark a point to track ( max points : 10
+);
+#X obj 112 546 unpack f f;
+#X floatatom 113 571 5 0 0 0 - - -;
+#X floatatom 171 572 5 0 0 0 - - -;
+#X text 114 587 X;
+#X text 169 588 Y;
+#X obj 112 525 route 1 2 3 4 5 6 7 8 9 10;
+#X text 144 623 <-- mark the points you want to track in the video
+window;
+#X text 280 527 position of each marked point;
+#X text 218 441 make a delaunay with all points;
+#X msg 137 439 delaunay on;
+#X msg 139 460 delaunay off;
+#X text 249 471 make a delaunay with point 1 and a tolerance of 50
+( all points which color is in that range will be included in the delaunay)
+;
+#X obj 168 324 hradio 15 1 0 8 empty empty empty 0 -8 0 10 -262144
+-1 -1 0;
+#X msg 145 483 pdelaunay 1 50;
+#X obj 20 499 pdp_opencv_surf;
+#X text -6 -112 pdp_opencv_surf : SURF ( Speed Up Robust Features )
+points detection and tracking;
+#X msg 31 209 hessian \$1;
+#X floatatom 106 210 5 0 0 0 - - -;
+#X text 146 209 hessian threshold ( default 500 );
+#X floatatom 214 401 5 0 0 0 - - -;
+#X msg 132 400 ftolerance \$1;
+#X text 257 401 frame tolerance for point recognition ( default : 5
+);
+#X msg 74 257 mark all;
+#X text 144 258 mark all points;
+#X msg 84 278 mark none;
+#X text 154 279 suppress all marks;
+#X connect 2 0 3 0;
+#X connect 3 0 5 0;
+#X connect 4 0 5 0;
+#X connect 5 0 57 0;
+#X connect 6 0 5 0;
+#X connect 7 0 8 0;
+#X connect 8 0 11 0;
+#X connect 9 0 11 0;
+#X connect 10 0 11 0;
+#X connect 11 0 57 0;
+#X connect 12 0 11 0;
+#X connect 13 0 12 0;
+#X connect 14 0 57 0;
+#X connect 15 0 14 0;
+#X connect 16 0 15 0;
+#X connect 17 0 15 0;
+#X connect 18 0 19 0;
+#X connect 19 0 14 0;
+#X connect 20 0 18 0;
+#X connect 21 0 14 0;
+#X connect 22 0 21 0;
+#X connect 23 0 22 0;
+#X connect 23 0 16 0;
+#X connect 26 0 14 1;
+#X connect 28 0 33 0;
+#X connect 29 0 30 0;
+#X connect 30 0 57 0;
+#X connect 32 0 28 0;
+#X connect 33 0 34 0;
+#X connect 34 0 57 0;
+#X connect 35 0 57 0;
+#X connect 37 0 57 0;
+#X connect 39 0 57 0;
+#X connect 41 0 39 0;
+#X connect 43 0 44 0;
+#X connect 43 1 45 0;
+#X connect 48 0 43 0;
+#X connect 52 0 57 0;
+#X connect 53 0 57 0;
+#X connect 55 0 35 0;
+#X connect 56 0 57 0;
+#X connect 57 0 28 0;
+#X connect 57 0 32 0;
+#X connect 57 1 48 0;
+#X connect 59 0 57 0;
+#X connect 60 0 59 0;
+#X connect 62 0 63 0;
+#X connect 63 0 57 0;
+#X connect 65 0 57 0;
+#X connect 67 0 57 0;
diff --git a/pdp_opencv_surf.cc b/pdp_opencv_surf.cc
new file mode 100644
index 0000000..268d1ab
--- /dev/null
+++ b/pdp_opencv_surf.cc
@@ -0,0 +1,690 @@
+/*
+ * Pure Data Packet module.
+ * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <dirent.h>
+#include <limits.h>
+#include <dlfcn.h>
+#include <ctype.h>
+
+#include "pdp.h"
+
+#ifndef _EiC
+#include "cv.h"
+#endif
+
+#define MAX_MARKERS 500
+#define DSCSIZE 128
+
+typedef struct pdp_opencv_surf_struct
+{
+ t_object x_obj;
+ t_float x_f;
+
+ t_outlet *x_outlet0;
+ t_outlet *x_outlet1;
+ t_atom x_list[3];
+
+ int x_packet0;
+ int x_packet1;
+ int x_dropped;
+ int x_queue_id;
+
+ int x_width;
+ int x_height;
+ int x_size;
+
+ int x_maxmove;
+ int x_delaunay;
+ int x_threshold;
+ int night_mode;
+ int x_markall;
+ int x_xmark[MAX_MARKERS];
+ int x_ymark[MAX_MARKERS];
+ float x_rdesc[MAX_MARKERS][DSCSIZE];
+ int x_found[MAX_MARKERS];
+
+ // The output and temporary images
+ IplImage *image, *oimage, *grey;
+
+ CvSeq *objectKeypoints, *objectDescriptors;
+ int x_hessian;
+ int x_criteria;
+ int x_ftolerance;
+
+ CvFont font;
+
+ // structures needed for the delaunay
+ CvRect x_fullrect;
+ CvMemStorage* x_storage;
+ CvSubdiv2D* x_subdiv;
+
+} t_pdp_opencv_surf;
+
+static void pdp_opencv_surf_mark(t_pdp_opencv_surf *x, t_symbol *s, int argc, t_atom *argv );
+
+static void pdp_opencv_surf_clear(t_pdp_opencv_surf *x );
+
+static double pdp_opencv_surf_compare_descriptors( const float* d1, const float* d2, int length )
+{
+ double total_cost = 0;
+ assert( length % 4 == 0 );
+ for( int i = 0; i < length; i += 4 )
+ {
+ double t0 = d1[i] - d2[i];
+ double t1 = d1[i+1] - d2[i+1];
+ double t2 = d1[i+2] - d2[i+2];
+ double t3 = d1[i+3] - d2[i+3];
+ total_cost += t0*t0 + t1*t1 + t2*t2 + t3*t3;
+ }
+ return total_cost;
+}
+
+static void pdp_opencv_surf_process_rgb(t_pdp_opencv_surf *x)
+{
+ t_pdp *header = pdp_packet_header(x->x_packet0);
+ short int *data = (short int *)pdp_packet_data(x->x_packet0);
+ t_pdp *newheader = pdp_packet_header(x->x_packet1);
+ short int *newdata = (short int *)pdp_packet_data(x->x_packet1);
+ int i,j,k,im;
+ char tindex[4];
+ int descsize;
+
+ if ((x->x_width != (t_int)header->info.image.width) ||
+ (x->x_height != (t_int)header->info.image.height) || (!x->image))
+ {
+
+ post("pdp_opencv_surf :: resizing plugins");
+
+ x->x_width = header->info.image.width;
+ x->x_height = header->info.image.height;
+ x->x_size = x->x_width*x->x_height;
+
+ //Destroy cv_images
+ if ( x->image )
+ {
+ cvReleaseImage( &x->image );
+ cvReleaseImage( &x->oimage );
+ cvReleaseImage( &x->grey );
+ }
+
+ //Create cv_images
+ x->image = cvCreateImage( cvSize(x->x_width, x->x_height), 8, 3 );
+ x->oimage = cvCreateImage( cvSize(x->x_width, x->x_height), 8, 3 );
+ x->grey = cvCreateImage( cvSize(x->x_width, x->x_height), 8, 1 );
+ }
+
+ newheader->info.image.encoding = header->info.image.encoding;
+ newheader->info.image.width = x->x_width;
+ newheader->info.image.height = x->x_height;
+
+ memcpy( newdata, data, x->x_size*3 );
+
+ memcpy( x->image->imageData, data, x->x_size*3 );
+ memcpy( x->oimage->imageData, data, x->x_size*3 );
+
+ cvCvtColor( x->image, x->grey, CV_RGB2GRAY );
+
+ x->x_storage = cvCreateMemStorage(0);
+
+ if( x->night_mode )
+ cvZero( x->image );
+
+ for ( im=0; im<MAX_MARKERS; im++ )
+ {
+ x->x_found[im]--;
+ }
+
+ if ( x->x_delaunay >= 0 )
+ {
+ // init data structures for the delaunay
+ x->x_fullrect.x = -x->x_width/2;
+ x->x_fullrect.y = -x->x_height/2;
+ x->x_fullrect.width = 2*x->x_width;
+ x->x_fullrect.height = 2*x->x_height;
+
+ x->x_subdiv = cvCreateSubdiv2D( CV_SEQ_KIND_SUBDIV2D, sizeof(*x->x_subdiv),
+ sizeof(CvSubdiv2DPoint),
+ sizeof(CvQuadEdge2D),
+ x->x_storage );
+ cvInitSubdivDelaunay2D( x->x_subdiv, x->x_fullrect );
+ }
+
+ cvExtractSURF( x->grey, 0, &x->objectKeypoints, &x->objectDescriptors, x->x_storage, cvSURFParams(x->x_hessian, 1) );
+ descsize = (int)(x->objectDescriptors->elem_size/sizeof(float));
+
+ for( i = 0; i < x->objectKeypoints->total; i++ )
+ {
+ CvSURFPoint* r1 = (CvSURFPoint*)cvGetSeqElem( x->objectKeypoints, i );
+ const float* rdesc = (const float*)cvGetSeqElem( x->objectDescriptors, i );
+
+ if ( x->x_delaunay == 0 ) // add all the points
+ {
+ cvSubdivDelaunay2DInsert( x->x_subdiv, r1->pt );
+ cvCalcSubdivVoronoi2D( x->x_subdiv );
+ }
+
+ // only add points included in (color-threshold)<p<(color+treshold)
+ if ( ( x->x_delaunay > 0 ) && ( x->x_xmark[x->x_delaunay-1] != -1 ) )
+ {
+ int px = cvPointFrom32f(r1->pt).x;
+ int py = cvPointFrom32f(r1->pt).y;
+ int ppx, ppy;
+
+ // eight connected pixels
+ for ( ppx=px-1; ppx<=px+1; ppx++ )
+ {
+ for ( ppy=py-1; ppy<=py+1; ppy++ )
+ {
+ if ( ( ppx < 0 ) || ( ppx >= x->x_width ) ) continue;
+ if ( ( ppy < 0 ) || ( ppy >= x->x_height ) ) continue;
+
+ uchar red = ((uchar*)(x->oimage->imageData + x->oimage->widthStep*ppx))[ppy*3];
+ uchar green = ((uchar*)(x->oimage->imageData + x->oimage->widthStep*ppx))[ppy*3+1];
+ uchar blue = ((uchar*)(x->oimage->imageData + x->oimage->widthStep*ppx))[ppy*3+2];
+
+ uchar pred = ((uchar*)(x->oimage->imageData + x->oimage->widthStep*x->x_xmark[x->x_delaunay-1]))[x->x_ymark[x->x_delaunay-1]*3];
+ uchar pgreen = ((uchar*)(x->oimage->imageData + x->oimage->widthStep*x->x_xmark[x->x_delaunay-1]))[x->x_ymark[x->x_delaunay-1]*3+1];
+ uchar pblue = ((uchar*)(x->oimage->imageData + x->oimage->widthStep*x->x_xmark[x->x_delaunay-1]))[x->x_ymark[x->x_delaunay-1]*3+2];
+
+ int diff = abs(red-pred) + abs(green-pgreen) + abs(blue-pblue);
+
+ // post( "pdp_opencv_surf : point (%d,%d,%d) : diff : %d", blue, green, red, diff );
+
+ if ( diff < x->x_threshold )
+ {
+ cvSubdivDelaunay2DInsert( x->x_subdiv, r1->pt );
+ cvCalcSubdivVoronoi2D( x->x_subdiv );
+ }
+ }
+ }
+ }
+
+ cvCircle( x->image, cvPointFrom32f(r1->pt), 3, CV_RGB(0,255,0), -1, 8,0);
+
+ // mark the point if it is not already
+ if ( x->x_markall )
+ {
+ int marked = 0;
+
+ for ( im=0; im<MAX_MARKERS; im++ )
+ {
+ if ( x->x_xmark[im] != -1.0 )
+ {
+ if ( ( abs( r1->pt.x - x->x_xmark[im] ) <= x->x_maxmove ) && ( abs( r1->pt.y - x->x_ymark[im] ) <= x->x_maxmove ) )
+ {
+ marked = 1;
+ // post( "pdp_opencv_surf : point already marked" );
+ break;
+ }
+ }
+ }
+ if ( !marked )
+ {
+ for ( i=0; i<MAX_MARKERS; i++)
+ {
+ if ( x->x_xmark[i] == -1 )
+ {
+ x->x_xmark[i] = r1->pt.x;
+ x->x_ymark[i] = r1->pt.y;
+ x->x_found[i] = x->x_ftolerance;
+ memset( (float * )x->x_rdesc[i], 0x0, DSCSIZE*sizeof(float));
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ for ( im=0; im<MAX_MARKERS; im++ )
+ {
+ int neighbour = -1;
+ double d, dist1 = 1000000, dist2 = 1000000;
+
+ for( i = 0; i < x->objectKeypoints->total; i++ )
+ {
+ CvSURFPoint* r1 = (CvSURFPoint*)cvGetSeqElem( x->objectKeypoints, i );
+ const float* rdesc = (const float*)cvGetSeqElem( x->objectDescriptors, i );
+ int descsize = (int)(x->objectDescriptors->elem_size/sizeof(float));
+
+ // manually marked points
+ // recognized on position
+ // if ( ( x->x_xmark[im] != -1.0 ) && ( x->x_rdesc[im][0] == 0.0 ) )
+ if ( x->x_xmark[im] != -1.0 )
+ {
+ if ( ( abs( r1->pt.x - x->x_xmark[im] ) <= x->x_maxmove ) && ( abs( r1->pt.y - x->x_ymark[im] ) <= x->x_maxmove ) )
+ {
+ sprintf( tindex, "%d", im+1 );
+ cvPutText( x->image, tindex, cvPointFrom32f(r1->pt), &x->font, CV_RGB(255,255,255));
+ x->x_xmark[im]=r1->pt.x;
+ x->x_ymark[im]=r1->pt.y;
+ memcpy( (float * )x->x_rdesc[im], rdesc, descsize*sizeof(float));
+ x->x_found[im]++;
+ SETFLOAT(&x->x_list[0], im+1);
+ SETFLOAT(&x->x_list[1], x->x_xmark[im]);
+ SETFLOAT(&x->x_list[2], x->x_ymark[im]);
+ outlet_list( x->x_outlet1, 0, 3, x->x_list );
+ break;
+ }
+ }
+
+ // recognize points according to their SURF descriptor ( size = 128 )
+ // this code is desactivated because it isn't more stable than the positions
+ // if ( ( x->x_xmark[im] != -1.0 ) && ( x->x_rdesc[im][0] != 0.0 ) )
+ // {
+ // d = pdp_opencv_surf_compare_descriptors( x->x_rdesc[im], rdesc, descsize );
+ // if( d < dist1 )
+ // {
+ // dist1 = d;
+ // neighbour = i;
+ // // post( "pdp_opencv_surf : point %d, min distance : %d ( with %d )", i, (int)d, im );
+ // }
+ // }
+ }
+
+ // check if we found the point
+ // if ( dist1 < x->x_criteria )
+ // {
+ // CvSURFPoint* r1 = (CvSURFPoint*)cvGetSeqElem( x->objectKeypoints, neighbour );
+ // const float* rdesc = (const float*)cvGetSeqElem( x->objectDescriptors, neighbour );
+
+ // // point identified
+ // sprintf( tindex, "%d", im+1 );
+ // cvPutText( x->image, tindex, cvPointFrom32f(r1->pt), &x->font, CV_RGB(255,255,255));
+ // x->x_xmark[im]=r1->pt.x;
+ // x->x_ymark[im]=r1->pt.y;
+ // memcpy( (float * )x->x_rdesc[im], rdesc, descsize*sizeof(float));
+ // x->x_found[im]=1;
+ // SETFLOAT(&x->x_list[0], im+1);
+ // SETFLOAT(&x->x_list[1], x->x_xmark[im]);
+ // SETFLOAT(&x->x_list[2], x->x_ymark[im]);
+ // outlet_list( x->x_outlet1, 0, 3, x->x_list );
+ // }
+ }
+
+ // draw the delaunay
+ if ( x->x_delaunay >= 0 )
+ {
+ CvSeqReader reader;
+ int i, total = x->x_subdiv->edges->total;
+ int elem_size = x->x_subdiv->edges->elem_size;
+
+ cvStartReadSeq( (CvSeq*)(x->x_subdiv->edges), &reader, 0 );
+
+ for( i = 0; i < total; i++ )
+ {
+ CvQuadEdge2D* edge = (CvQuadEdge2D*)(reader.ptr);
+ CvSubdiv2DPoint* org_pt;
+ CvSubdiv2DPoint* dst_pt;
+ CvPoint2D32f org;
+ CvPoint2D32f dst;
+ CvPoint iorg, idst;
+
+ if( CV_IS_SET_ELEM( edge ))
+ {
+ org_pt = cvSubdiv2DEdgeOrg((CvSubdiv2DEdge)edge);
+ dst_pt = cvSubdiv2DEdgeDst((CvSubdiv2DEdge)edge);
+
+ if( org_pt && dst_pt )
+ {
+ org = org_pt->pt;
+ dst = dst_pt->pt;
+
+ iorg = cvPoint( cvRound( org.x ), cvRound( org.y ));
+ idst = cvPoint( cvRound( dst.x ), cvRound( dst.y ));
+
+ if ( ( org.x > 0 ) && ( org.x < x->x_width ) &&
+ ( dst.x > 0 ) && ( dst.x < x->x_width ) &&
+ ( org.y > 0 ) && ( org.y < x->x_height ) &&
+ ( dst.y > 0 ) && ( dst.y < x->x_height ) )
+ cvLine( x->image, iorg, idst, CV_RGB(255,0,0), 1, CV_AA, 0 );
+ }
+ }
+
+ // draw the voronoi : useless in my opinion as points belongs to contours
+ /*
+ if( CV_IS_SET_ELEM( edge+1 ))
+ {
+ org_pt = cvSubdiv2DEdgeOrg((CvSubdiv2DEdge)edge+1);
+ dst_pt = cvSubdiv2DEdgeDst((CvSubdiv2DEdge)edge+1);
+
+ if( org_pt && dst_pt )
+ {
+ org = org_pt->pt;
+ dst = dst_pt->pt;
+
+ iorg = cvPoint( cvRound( org.x ), cvRound( org.y ));
+ idst = cvPoint( cvRound( dst.x ), cvRound( dst.y ));
+
+ cvLine( x->image, iorg, idst, CV_RGB(0,0,255), 1, CV_AA, 0 );
+ }
+ }
+ */
+
+ CV_NEXT_SEQ_ELEM( elem_size, reader );
+ }
+ }
+
+ // suppress lost points
+ for ( im=0; im<MAX_MARKERS; im++ )
+ {
+ if ( (x->x_xmark[im] != -1.0 ) && !x->x_found[im] )
+ {
+ x->x_xmark[im]=-1.0;
+ x->x_ymark[im]=-1.0;
+ SETFLOAT(&x->x_list[0], im+1);
+ SETFLOAT(&x->x_list[1], x->x_xmark[im]);
+ SETFLOAT(&x->x_list[2], x->x_ymark[im]);
+ // send a lost point message to the patch
+ outlet_list( x->x_outlet1, 0, 3, x->x_list );
+ // post( "pdp_opencv_surf : lost point %d", im+1 );
+ }
+ }
+
+ memcpy( newdata, x->image->imageData, x->x_size*3 );
+
+ cvReleaseMemStorage( &x->x_storage );
+
+ return;
+}
+
+
+static void pdp_opencv_surf_nightmode(t_pdp_opencv_surf *x, t_floatarg f)
+{
+ if ((f==0.0)||(f==1.0)) x->night_mode = (int)f;
+}
+
+static void pdp_opencv_surf_ftolerance(t_pdp_opencv_surf *x, t_floatarg f)
+{
+ if (f>0.0) x->x_ftolerance = (int)f;
+}
+
+static void pdp_opencv_surf_maxmove(t_pdp_opencv_surf *x, t_floatarg f)
+{
+ // has to be more than the size of a point
+ if (f>=3.0) x->x_maxmove = (int)f;
+}
+
+static void pdp_opencv_surf_hessian(t_pdp_opencv_surf *x, t_floatarg f)
+{
+ if ( (int)f>0 ) x->x_hessian = (int)f;
+}
+
+static void pdp_opencv_surf_criteria(t_pdp_opencv_surf *x, t_floatarg f)
+{
+ if ( (int)f>0 ) x->x_criteria = (int)f;
+}
+
+static void pdp_opencv_surf_delaunay(t_pdp_opencv_surf *x, t_symbol *s)
+{
+ if (s == gensym("on"))
+ x->x_delaunay = 0;
+ if (s == gensym("off"))
+ x->x_delaunay = -1;
+}
+
+static void pdp_opencv_surf_pdelaunay(t_pdp_opencv_surf *x, t_floatarg point, t_floatarg threshold)
+{
+ if (((int)point>0) && ((int)point<MAX_MARKERS))
+ {
+ x->x_delaunay = (int)point;
+ x->x_threshold = (int)threshold;
+ }
+}
+
+static void pdp_opencv_surf_mark(t_pdp_opencv_surf *x, t_symbol *s, int argc, t_atom *argv )
+{
+ int i;
+ int inserted;
+ int px,py;
+
+ if ( argc == 1 ) // mark all
+ {
+ if ( argv[0].a_type != A_SYMBOL )
+ {
+ error( "pdp_opencv_surf : wrong argument (should be 'all')" );
+ return;
+ }
+ if ( !strcmp( argv[0].a_w.w_symbol->s_name, "all" ) )
+ {
+ x->x_markall = 1;
+ return;
+ }
+ if ( !strcmp( argv[0].a_w.w_symbol->s_name, "none" ) )
+ {
+ x->x_markall = 0;
+ pdp_opencv_surf_clear(x);
+ return;
+ }
+ }
+ else
+ {
+ if ( ( argv[0].a_type != A_FLOAT ) || ( argv[1].a_type != A_FLOAT ) )
+ {
+ error( "pdp_opencv_surf : wrong argument (should be mark px py)" );
+ return;
+ }
+ else
+ {
+ float fperx = argv[0].a_w.w_float;
+ float fpery = argv[1].a_w.w_float;
+
+ if ( ( fperx < 0.0 ) || ( fperx > 1.0 ) || ( fpery < 0.0 ) || ( fpery > 1.0 ) )
+ {
+ return;
+ }
+
+ px = (int)(fperx*x->x_width);
+ py = (int)(fpery*x->x_height);
+ inserted = 0;
+ for ( i=0; i<MAX_MARKERS; i++)
+ {
+ if ( x->x_xmark[i] == -1 )
+ {
+ x->x_xmark[i] = px;
+ x->x_ymark[i] = py;
+ x->x_found[i] = x->x_ftolerance;
+ memset( (float * )x->x_rdesc[i], 0x0, DSCSIZE*sizeof(float));
+ inserted = 1;
+ break;
+ }
+ }
+ if ( !inserted )
+ {
+ post( "pdp_opencv_surf : max markers reached" );
+ }
+ }
+ }
+}
+
+static void pdp_opencv_surf_delete(t_pdp_opencv_surf *x, t_floatarg findex )
+{
+ int i;
+
+ if ( ( findex < 1.0 ) || ( findex > MAX_MARKERS ) )
+ {
+ return;
+ }
+
+ x->x_xmark[(int)findex-1] = -1;
+ x->x_ymark[(int)findex-1] = -1;
+}
+
+static void pdp_opencv_surf_clear(t_pdp_opencv_surf *x )
+{
+ int i;
+
+ for ( i=0; i<MAX_MARKERS; i++)
+ {
+ x->x_xmark[i] = -1;
+ x->x_ymark[i] = -1;
+ }
+}
+
+static void pdp_opencv_surf_sendpacket(t_pdp_opencv_surf *x)
+{
+ /* release the packet */
+ pdp_packet_mark_unused(x->x_packet0);
+ x->x_packet0 = -1;
+
+ /* unregister and propagate if valid dest packet */
+ pdp_packet_pass_if_valid(x->x_outlet0, &x->x_packet1);
+}
+
+static void pdp_opencv_surf_process(t_pdp_opencv_surf *x)
+{
+ int encoding;
+ t_pdp *header = 0;
+ char *parname;
+ unsigned pi;
+ int partype;
+ float pardefault;
+ t_atom plist[2];
+ t_atom tlist[2];
+ t_atom vlist[2];
+
+ /* check if image data packets are compatible */
+ if ( (header = pdp_packet_header(x->x_packet0))
+ && (PDP_BITMAP == header->type)){
+
+ /* pdp_opencv_surf_process inputs and write into active inlet */
+ switch(pdp_packet_header(x->x_packet0)->info.image.encoding){
+
+ case PDP_BITMAP_RGB:
+ x->x_packet1 = pdp_packet_clone_rw(x->x_packet0);
+ pdp_queue_add(x, (void*)pdp_opencv_surf_process_rgb, (void*)pdp_opencv_surf_sendpacket, &x->x_queue_id);
+ break;
+
+ default:
+ /* don't know the type, so dont pdp_opencv_surf_process */
+ break;
+
+ }
+ }
+
+}
+
+static void pdp_opencv_surf_input_0(t_pdp_opencv_surf *x, t_symbol *s, t_floatarg f)
+{
+ /* if this is a register_ro message or register_rw message, register with packet factory */
+
+ if (s == gensym("register_rw"))
+ x->x_dropped = pdp_packet_convert_ro_or_drop(&x->x_packet0, (int)f, pdp_gensym((char *)"bitmap/rgb/*") );
+
+ if ((s == gensym("process")) && (-1 != x->x_packet0) && (!x->x_dropped))
+ {
+ /* add the process method and callback to the process queue */
+ pdp_opencv_surf_process(x);
+ }
+}
+
+static void pdp_opencv_surf_free(t_pdp_opencv_surf *x)
+{
+ int i;
+
+ pdp_queue_finish(x->x_queue_id);
+ pdp_packet_mark_unused(x->x_packet0);
+
+ //Destroy cv_images
+ cvReleaseImage( &x->image );
+ cvReleaseImage( &x->grey );
+}
+
+t_class *pdp_opencv_surf_class;
+
+
+void *pdp_opencv_surf_new(t_floatarg f)
+{
+ int i;
+
+ t_pdp_opencv_surf *x = (t_pdp_opencv_surf *)pd_new(pdp_opencv_surf_class);
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("win_size"));
+
+ x->x_outlet0 = outlet_new(&x->x_obj, &s_anything);
+ x->x_outlet1 = outlet_new(&x->x_obj, &s_anything);
+
+ x->x_packet0 = -1;
+ x->x_packet1 = -1;
+ x->x_queue_id = -1;
+
+ x->x_width = 320;
+ x->x_height = 240;
+ x->x_size = x->x_width * x->x_height;
+
+ x->night_mode = 0;
+ x->x_maxmove = 8;
+ x->x_delaunay = -1;
+ x->x_threshold = -1;
+
+ x->objectKeypoints = NULL;
+ x->objectDescriptors = NULL;
+ x->x_hessian = 500;
+ x->x_criteria = 20;
+ x->x_ftolerance = 5;
+
+ x->x_markall = 0;
+ for ( i=0; i<MAX_MARKERS; i++ )
+ {
+ x->x_xmark[i] = -1;
+ x->x_ymark[i] = -1;
+ }
+
+ // initialize font
+ cvInitFont( &x->font, CV_FONT_HERSHEY_PLAIN, 1.0, 1.0, 0, 1, 8 );
+
+ x->image = cvCreateImage( cvSize(x->x_width, x->x_height), 8, 3 );
+ x->oimage = cvCreateImage( cvSize(x->x_width, x->x_height), 8, 3 );
+ x->grey = cvCreateImage( cvSize(x->x_width, x->x_height), 8, 1 );
+
+ return (void *)x;
+}
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+void pdp_opencv_surf_setup(void)
+{
+
+ post( " pdp_opencv_surf");
+ pdp_opencv_surf_class = class_new(gensym("pdp_opencv_surf"), (t_newmethod)pdp_opencv_surf_new,
+ (t_method)pdp_opencv_surf_free, sizeof(t_pdp_opencv_surf), 0, A_DEFFLOAT, A_NULL);
+
+ class_addmethod(pdp_opencv_surf_class, (t_method)pdp_opencv_surf_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL);
+ class_addmethod(pdp_opencv_surf_class, (t_method)pdp_opencv_surf_nightmode, gensym("nightmode"), A_FLOAT, A_NULL );
+ class_addmethod(pdp_opencv_surf_class, (t_method)pdp_opencv_surf_hessian, gensym("hessian"), A_FLOAT, A_NULL );
+ class_addmethod(pdp_opencv_surf_class, (t_method)pdp_opencv_surf_ftolerance, gensym("ftolerance"), A_FLOAT, A_NULL );
+ class_addmethod(pdp_opencv_surf_class, (t_method)pdp_opencv_surf_mark, gensym("mark"), A_GIMME, A_NULL );
+ class_addmethod(pdp_opencv_surf_class, (t_method)pdp_opencv_surf_delete, gensym("delete"), A_FLOAT, A_NULL );
+ class_addmethod(pdp_opencv_surf_class, (t_method)pdp_opencv_surf_clear, gensym("clear"), A_NULL );
+ class_addmethod(pdp_opencv_surf_class, (t_method)pdp_opencv_surf_maxmove, gensym("maxmove"), A_FLOAT, A_NULL );
+ class_addmethod(pdp_opencv_surf_class, (t_method)pdp_opencv_surf_delaunay, gensym("delaunay"), A_SYMBOL, A_NULL );
+ class_addmethod(pdp_opencv_surf_class, (t_method)pdp_opencv_surf_pdelaunay, gensym("pdelaunay"), A_FLOAT, A_FLOAT, A_NULL );
+
+}
+
+#ifdef __cplusplus
+}
+#endif