aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pdp_opencv_contours_boundingrect-help.pd36
-rw-r--r--pdp_opencv_contours_boundingrect.c89
2 files changed, 101 insertions, 24 deletions
diff --git a/pdp_opencv_contours_boundingrect-help.pd b/pdp_opencv_contours_boundingrect-help.pd
index 86217dc..346540f 100644
--- a/pdp_opencv_contours_boundingrect-help.pd
+++ b/pdp_opencv_contours_boundingrect-help.pd
@@ -1,4 +1,4 @@
-#N canvas 159 107 1249 684 10;
+#N canvas 164 131 1249 684 10;
#X obj 41 -82 cnv 15 621 223 empty empty empty 20 12 0 14 -260097 -66577
0;
#X obj 91 75 pdp_1394L;
@@ -25,7 +25,7 @@
#X obj 91 189 pdp_convert bitmap/rgb/*;
#X text 255 183 COLORMODEL CONVERSION :: allways remember pdp_opencv
only works in RGB colormodel;
-#X obj 47 337 cnv 15 621 313 empty empty empty 20 12 0 14 -258113 -66577
+#X obj 48 328 cnv 15 621 313 empty empty empty 20 12 0 14 -258113 -66577
0;
#X text 71 -79 FIRST OF ALL SETUP YOUR CAMERA;
#X floatatom 185 509 5 0 0 0 - - -;
@@ -33,10 +33,10 @@ only works in RGB colormodel;
#X floatatom 257 509 5 0 0 0 - - -;
#X floatatom 291 509 5 0 0 0 - - -;
#X obj 185 482 unpack 0 0 0 0 0;
-#X obj 185 446 route 0 1 2 3 4;
-#X floatatom 244 347 5 0 0 0 - - -;
-#X floatatom 268 365 5 0 0 0 - - -;
-#X obj 91 387 pdp_opencv_contours_boundingrect;
+#X obj 185 461 route 0 1 2 3 4;
+#X floatatom 211 385 5 0 0 0 - - -;
+#X floatatom 283 398 5 0 0 0 - - -;
+#X obj 93 413 pdp_opencv_contours_boundingrect;
#X text 335 509 Xorigin Yorigin Width Height;
#X floatatom 205 565 5 0 0 0 - - -;
#X floatatom 240 565 5 0 0 0 - - -;
@@ -67,23 +67,31 @@ white areas in the input image \, it's important to set max/min values
of the areas you want to detect to filter non interesting noise or
areas \, also sometimes you will need to use pdp_opencv_morphology
to transform the contours of the shapes to be analyzed..;
-#X floatatom 278 409 5 0 0 0 - - -;
-#X text 317 410 Number of detected contours;
+#X floatatom 280 435 5 0 0 0 - - -;
+#X text 319 436 Number of detected contours;
#X floatatom 230 623 5 0 0 0 - - -;
#X floatatom 265 623 5 0 0 0 - - -;
#X floatatom 302 623 5 0 0 0 - - -;
#X floatatom 336 623 5 0 0 0 - - -;
#X obj 227 594 unpack 0 0 0 0 0;
#X text 380 623 Xorigin Yorigin Width Height;
-#X text 288 451 For each contour detected;
-#X text 288 438 We have the contours sorted bottom to top and left
+#X text 288 466 For each contour detected;
+#X text 288 453 We have the contours sorted bottom to top and left
to right;
#X text 42 -273 It is useful as a motion tracker if you have well isolated
silouets of the objects you want to track.;
-#X text 280 349 minimal area in pixels to be detected (default 10x10)
+#X text 249 383 minimal area in pixels to be detected (default 10x10)
;
-#X text 302 367 maximal area in pixels to be detected (default 320x240)
+#X text 320 399 maximal area in pixels to be detected (default 320x240)
;
+#X msg 138 335 mode \$1;
+#X obj 199 336 hradio 15 1 0 4 empty empty empty 0 -8 0 10 -262144
+-1 -1 0;
+#X text 268 337 retrieval mode ( see cvFindContours );
+#X obj 242 364 hradio 15 1 0 5 empty empty empty 0 -8 0 10 -262144
+-1 -1 0;
+#X text 318 364 retrieval method ( see cvFindContours );
+#X msg 175 363 method \$1;
#X connect 1 0 18 0;
#X connect 2 0 1 0;
#X connect 3 0 4 0;
@@ -126,3 +134,7 @@ silouets of the objects you want to track.;
#X connect 56 1 53 0;
#X connect 56 2 54 0;
#X connect 56 3 55 0;
+#X connect 63 0 30 0;
+#X connect 64 0 63 0;
+#X connect 66 0 68 0;
+#X connect 68 0 30 0;
diff --git a/pdp_opencv_contours_boundingrect.c b/pdp_opencv_contours_boundingrect.c
index 714dc26..da07cf1 100644
--- a/pdp_opencv_contours_boundingrect.c
+++ b/pdp_opencv_contours_boundingrect.c
@@ -53,6 +53,11 @@ typedef struct pdp_opencv_contours_boundingrect_struct
int x_ftolerance;
int x_mmove;
+ // contours retrieval mode
+ int x_cmode;
+ // contours retrieval method
+ int x_cmethod;
+
int x_width;
int x_height;
int x_size;
@@ -86,7 +91,7 @@ static int pdp_opencv_contours_boundingrect_mark(t_pdp_opencv_contours_boundingr
}
}
- post( "pdp_opencv_contours_boundingrect : max markers reached" );
+ // post( "pdp_opencv_contours_boundingrect : max markers reached" );
return -1;
}
@@ -129,7 +134,6 @@ static void pdp_opencv_contours_boundingrect_process_rgb(t_pdp_opencv_contours_b
newheader->info.image.width = x->x_width;
newheader->info.image.height = x->x_height;
- // FEM UNA COPIA DEL PACKET A image->imageData ... http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html aqui veiem la estructura de IplImage
memcpy( x->image->imageData, data, x->x_size*3 );
// Convert to grayscale
@@ -149,12 +153,12 @@ static void pdp_opencv_contours_boundingrect_process_rgb(t_pdp_opencv_contours_b
//ContourBoundingRect
//
- // TODO afegir parametres
// Retrieval mode.
- // CV_RETR_TREE || CV_RETR_CCOMP || CV_RETR_LIST || CV_RETR_EXTERNAL
+ // CV_RETR_EXTERNAL || CV_RETR_LIST || CV_RETR_CCOMP || CV_RETR_TREE
// Approximation method.
- // CV_CHAIN_APPROX_SIMPLE || CV_CHAIN_CODE || CV_CHAIN_APPROX_NONE || CV_CHAIN_APPROX_TC89_L1 || CV_CHAIN_APPROX_TC89_KCOS || CV_LINK_RUNS
- cvFindContours( x->gray, stor02, &contours, sizeof(CvContour), CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0) );
+ // CV_CHAIN_CODE || CV_CHAIN_APPROX_NONE || CV_CHAIN_APPROX_SIMPLE || CV_CHAIN_APPROX_TC89_L1 || CV_CHAIN_APPROX_TC89_KCOS || CV_LINK_RUNS
+ cvFindContours( x->gray, stor02, &contours, sizeof(CvContour), x->x_cmode, x->x_cmethod, cvPoint(0,0) );
+
// TODO afegir parametres
// aqui es fa una aproximacio del contorn per a que sigui mes polinomic i no tingui tants punts
// els ultims dos parametres han de ser variables
@@ -228,7 +232,6 @@ static void pdp_opencv_contours_boundingrect_process_rgb(t_pdp_opencv_contours_b
x->x_xmark[im] = -1.0;
x->x_ymark[im] = -1,0;
x->x_found[im] = x->x_ftolerance;
- post( "deleted point %d", im );
}
}
@@ -239,11 +242,6 @@ static void pdp_opencv_contours_boundingrect_process_rgb(t_pdp_opencv_contours_b
return;
}
-static void pdp_opencv_contours_boundingrect_param(t_pdp_opencv_contours_boundingrect *x, t_floatarg f1, t_floatarg f2)
-{
-
-}
-
static void pdp_opencv_contours_boundingrect_minarea(t_pdp_opencv_contours_boundingrect *x, t_floatarg f)
{
x->minarea = (int)f;
@@ -264,6 +262,69 @@ static void pdp_opencv_contours_boundingrect_mmove(t_pdp_opencv_contours_boundin
if ((int)f>=1) x->x_mmove = (int)f;
}
+static void pdp_opencv_contours_boundingrect_cmode(t_pdp_opencv_contours_boundingrect *x, t_floatarg f)
+{
+ // CV_RETR_EXTERNAL || CV_RETR_LIST || CV_RETR_CCOMP || CV_RETR_TREE
+ int mode = (int)f;
+
+ if ( mode == CV_RETR_EXTERNAL )
+ {
+ x->x_cmode = CV_RETR_EXTERNAL;
+ post( "pdp_opencv_contours_boundingrect : mode set to CV_RETR_EXTERNAL" );
+ }
+ if ( mode == CV_RETR_LIST )
+ {
+ x->x_cmode = CV_RETR_LIST;
+ post( "pdp_opencv_contours_boundingrect : mode set to CV_RETR_LIST" );
+ }
+ if ( mode == CV_RETR_CCOMP )
+ {
+ x->x_cmode = CV_RETR_CCOMP;
+ post( "pdp_opencv_contours_boundingrect : mode set to CV_RETR_CCOMP" );
+ }
+ if ( mode == CV_RETR_TREE )
+ {
+ x->x_cmode = CV_RETR_TREE;
+ post( "pdp_opencv_contours_boundingrect : mode set to CV_RETR_TREE" );
+ }
+}
+
+static void pdp_opencv_contours_boundingrect_cmethod(t_pdp_opencv_contours_boundingrect *x, t_floatarg f)
+{
+ int method = (int)f;
+
+ // CV_CHAIN_CODE || CV_CHAIN_APPROX_NONE || CV_CHAIN_APPROX_SIMPLE || CV_CHAIN_APPROX_TC89_L1 || CV_CHAIN_APPROX_TC89_KCOS || CV_LINK_RUNS
+ if ( method == CV_CHAIN_CODE )
+ {
+ post( "pdp_opencv_contours_boundingrect : not supported method : CV_CHAIN_CODE" );
+ }
+ if ( method == CV_CHAIN_APPROX_NONE )
+ {
+ x->x_cmethod = CV_CHAIN_APPROX_NONE;
+ post( "pdp_opencv_contours_boundingrect : method set to CV_CHAIN_APPROX_NONE" );
+ }
+ if ( method == CV_CHAIN_APPROX_SIMPLE )
+ {
+ x->x_cmethod = CV_CHAIN_APPROX_SIMPLE;
+ post( "pdp_opencv_contours_boundingrect : method set to CV_CHAIN_APPROX_SIMPLE" );
+ }
+ if ( method == CV_CHAIN_APPROX_TC89_L1 )
+ {
+ x->x_cmethod = CV_CHAIN_APPROX_TC89_L1;
+ post( "pdp_opencv_contours_boundingrect : method set to CV_CHAIN_APPROX_TC89_L1" );
+ }
+ if ( method == CV_CHAIN_APPROX_TC89_KCOS )
+ {
+ x->x_cmethod = CV_CHAIN_APPROX_TC89_KCOS;
+ post( "pdp_opencv_contours_boundingrect : method set to CV_CHAIN_APPROX_TC89_KCOS" );
+ }
+ if ( ( method == CV_LINK_RUNS ) && ( x->x_cmode == CV_RETR_LIST ) )
+ {
+ x->x_cmethod = CV_LINK_RUNS;
+ post( "pdp_opencv_contours_boundingrect : method set to CV_LINK_RUNS" );
+ }
+}
+
static void pdp_opencv_contours_boundingrect_delete(t_pdp_opencv_contours_boundingrect *x, t_floatarg findex )
{
int i;
@@ -390,6 +451,8 @@ void *pdp_opencv_contours_boundingrect_new(t_floatarg f)
x->x_ftolerance = 5;
x->x_mmove = 5;
+ x->x_cmode = CV_RETR_TREE;
+ x->x_cmethod = CV_CHAIN_APPROX_SIMPLE;
x->image = cvCreateImage(cvSize(x->x_width,x->x_height), IPL_DEPTH_8U, 3);
x->gray = cvCreateImage(cvSize(x->image->width,x->image->height), IPL_DEPTH_8U, 1);
@@ -422,6 +485,8 @@ void pdp_opencv_contours_boundingrect_setup(void)
class_addmethod(pdp_opencv_contours_boundingrect_class, (t_method)pdp_opencv_contours_boundingrect_ftolerance, gensym("ftolerance"), A_FLOAT, A_NULL );
class_addmethod(pdp_opencv_contours_boundingrect_class, (t_method)pdp_opencv_contours_boundingrect_mmove, gensym("maxmove"), A_FLOAT, A_NULL );
class_addmethod(pdp_opencv_contours_boundingrect_class, (t_method)pdp_opencv_contours_boundingrect_clear, gensym("clear"), A_NULL );
+ class_addmethod(pdp_opencv_contours_boundingrect_class, (t_method)pdp_opencv_contours_boundingrect_cmode, gensym("mode"), A_FLOAT, A_NULL );
+ class_addmethod(pdp_opencv_contours_boundingrect_class, (t_method)pdp_opencv_contours_boundingrect_cmethod, gensym("method"), A_FLOAT, A_NULL );
}