diff options
author | N.N. <sevyves@users.sourceforge.net> | 2009-05-31 18:45:00 +0000 |
---|---|---|
committer | N.N. <sevyves@users.sourceforge.net> | 2009-05-31 18:45:00 +0000 |
commit | 3056cc264b82c49cb379b4fbc3a08beaa2119614 (patch) | |
tree | 520b058ed3459d2ee6c61f94f633614b2edb66f5 | |
parent | 14ecccfc24fdc05b2f6ff7926677461e9222acf6 (diff) |
fixed a few parameters ( duration, aperture )
svn path=/trunk/externals/pdp_opencv/; revision=11595
-rw-r--r-- | pdp_opencv_motempl-help.pd | 147 | ||||
-rw-r--r-- | pdp_opencv_motempl.c | 136 |
2 files changed, 153 insertions, 130 deletions
diff --git a/pdp_opencv_motempl-help.pd b/pdp_opencv_motempl-help.pd index bcbc2bb..a0af63d 100644 --- a/pdp_opencv_motempl-help.pd +++ b/pdp_opencv_motempl-help.pd @@ -1,10 +1,7 @@ -#N canvas 0 25 1247 665 10; +#N canvas 20 121 1247 665 10; #X floatatom 485 286 5 0 0 0 - - -; -#X floatatom 546 248 5 0 0 0 - - -; +#X floatatom 583 247 5 0 0 0 - - -; #X text 525 288 Threshold value. (default 30); -#X text 588 247 Maximal duration of motion track in seconds. (default -1); -#X text 550 266 xxx; #X obj 492 373 route -1 0 1 2 3 4; #X floatatom 495 453 5 0 0 0 - - -; #X floatatom 530 453 5 0 0 0 - - -; @@ -31,7 +28,7 @@ #X text 757 557 Xcenter Ycenter Width Height Angle; #X obj 360 329 pdp_opencv_motempl; #X obj 364 374 pdp_xv; -#X msg 430 246 mhi_duration \$1; +#X msg 479 244 mhi_duration \$1; #X obj 59 391 pdp_qt; #X obj 56 41 metro 40; #X msg 56 13 bang; @@ -51,65 +48,93 @@ #X msg 141 222 autoplay 1; #X msg 142 267 play; #X msg 142 315 cont; -#X floatatom 586 160 5 0 0 0 - - -; -#X msg 431 158 max_time_delta \$1; -#X floatatom 586 183 5 0 0 0 - - -; -#X msg 431 181 min_time_delta \$1; -#X floatatom 585 212 5 0 0 0 - - -; -#X msg 430 210 frame_buffer_num \$1; +#X floatatom 548 126 5 0 0 0 - - -; +#X msg 430 123 max_time_delta \$1; +#X floatatom 562 151 5 0 0 0 - - -; +#X msg 445 149 min_time_delta \$1; +#X floatatom 591 216 5 0 0 0 - - -; +#X msg 463 214 frame_buffer_num \$1; #X floatatom 512 304 5 0 0 0 - - -; #X floatatom 523 323 5 0 0 0 - - -; #X text 563 325 Max size of the motion component (default 500); #X text 553 304 Min size of the motion component (default 50); -#X text 627 211 Number of frames in the buffer. (default 4); -#X text 628 159 Max time delta in seconds. (default 0.5); -#X text 628 182 Min time delta in seconds. (default 0.05); -#X connect 0 0 29 1; -#X connect 1 0 31 0; -#X connect 5 0 18 0; -#X connect 5 1 19 0; -#X connect 5 2 20 0; -#X connect 18 0 6 0; -#X connect 18 1 7 0; -#X connect 18 2 8 0; -#X connect 18 3 9 0; +#X text 586 125 Max time delta in seconds. (default 0.5); +#X text 600 151 Min time delta in seconds. (default 0.05); +#X obj 231 72 pdp_v4l2; +#X obj 231 45 metro 40; +#X msg 231 20 bang; +#X obj 303 43 metro 40; +#X msg 303 18 bang; +#X obj 303 70 pdp_v4l; +#X text 51 557 written by Lluis Gomez i Bigorda ( lluisgomez@hangar.org +); +#X text 52 533 pdp_opencv_motempl : opencv motion detection based on +history; +#X text 632 216 Number of frames in the history buffer. (default 4) +; +#X text 625 248 Maximal duration of motion track in seconds. (default +1.0); +#X msg 456 180 aperture \$1; +#X text 653 177 aperture ( 3 \, 5 or 7 \, default 3 ); +#X msg 536 180 3; +#X msg 569 180 5; +#X msg 600 180 7; +#X connect 0 0 27 1; +#X connect 1 0 29 0; +#X connect 3 0 16 0; +#X connect 3 1 17 0; +#X connect 3 2 18 0; +#X connect 16 0 4 0; +#X connect 16 1 5 0; +#X connect 16 2 6 0; +#X connect 16 3 7 0; +#X connect 16 4 19 0; +#X connect 17 0 8 0; +#X connect 17 1 9 0; +#X connect 17 2 10 0; +#X connect 17 3 11 0; +#X connect 17 4 20 0; +#X connect 18 0 12 0; +#X connect 18 1 13 0; +#X connect 18 2 14 0; +#X connect 18 3 15 0; #X connect 18 4 21 0; -#X connect 19 0 10 0; -#X connect 19 1 11 0; -#X connect 19 2 12 0; -#X connect 19 3 13 0; -#X connect 19 4 22 0; -#X connect 20 0 14 0; -#X connect 20 1 15 0; -#X connect 20 2 16 0; -#X connect 20 3 17 0; -#X connect 20 4 23 0; -#X connect 29 0 30 0; -#X connect 29 1 5 0; -#X connect 31 0 29 0; -#X connect 32 0 29 0; -#X connect 33 0 32 0; -#X connect 34 0 33 0; -#X connect 35 0 33 0; -#X connect 36 0 32 0; -#X connect 37 0 38 0; -#X connect 38 0 32 0; -#X connect 39 0 37 0; -#X connect 40 0 32 0; -#X connect 41 0 32 0; -#X connect 42 0 32 1; -#X connect 43 0 32 0; -#X connect 44 0 43 0; -#X connect 45 0 32 0; -#X connect 46 0 32 0; -#X connect 47 0 32 0; -#X connect 48 0 32 0; -#X connect 49 0 32 0; +#X connect 27 0 28 0; +#X connect 27 1 3 0; +#X connect 29 0 27 0; +#X connect 30 0 27 0; +#X connect 31 0 30 0; +#X connect 32 0 31 0; +#X connect 33 0 31 0; +#X connect 34 0 30 0; +#X connect 35 0 36 0; +#X connect 36 0 30 0; +#X connect 37 0 35 0; +#X connect 38 0 30 0; +#X connect 39 0 30 0; +#X connect 40 0 30 1; +#X connect 41 0 30 0; +#X connect 42 0 41 0; +#X connect 43 0 30 0; +#X connect 44 0 30 0; +#X connect 45 0 30 0; +#X connect 46 0 30 0; +#X connect 47 0 30 0; +#X connect 48 0 49 0; +#X connect 49 0 27 0; #X connect 50 0 51 0; -#X connect 51 0 29 0; +#X connect 51 0 27 0; #X connect 52 0 53 0; -#X connect 53 0 29 0; -#X connect 54 0 55 0; -#X connect 55 0 29 0; -#X connect 56 0 29 2; -#X connect 57 0 29 3; +#X connect 53 0 27 0; +#X connect 54 0 27 2; +#X connect 55 0 27 3; +#X connect 60 0 27 0; +#X connect 61 0 60 0; +#X connect 62 0 61 0; +#X connect 63 0 65 0; +#X connect 64 0 63 0; +#X connect 65 0 27 0; +#X connect 70 0 27 0; +#X connect 72 0 70 0; +#X connect 73 0 70 0; +#X connect 74 0 70 0; diff --git a/pdp_opencv_motempl.c b/pdp_opencv_motempl.c index 1d850ee..e9989c0 100644 --- a/pdp_opencv_motempl.c +++ b/pdp_opencv_motempl.c @@ -34,8 +34,6 @@ #include <ctype.h> #endif - - typedef struct pdp_opencv_motempl_struct { t_object x_obj; @@ -53,7 +51,8 @@ typedef struct pdp_opencv_motempl_struct int x_size; int x_thresh; - int x_mhi_duration; + double x_mhi_duration; + int x_aperture; int x_infosok; @@ -74,6 +73,7 @@ typedef struct pdp_opencv_motempl_struct // various tracking parameters (in seconds) double max_time_delta; double min_time_delta; + // number of cyclic frame buffer used for motion detection // (should, probably, depend on FPS) int frame_buffer_num; @@ -81,6 +81,8 @@ typedef struct pdp_opencv_motempl_struct int max_size; int min_size; + t_atom rlist[6]; + } t_pdp_opencv_motempl; void pdp_opencv_motempl_update_mhi( t_pdp_opencv_motempl *x, IplImage* img, IplImage* dst, int diff_threshold ) @@ -140,7 +142,7 @@ void pdp_opencv_motempl_update_mhi( t_pdp_opencv_motempl *x, IplImage* img, Ipl cvCvtPlaneToPix( x->mask, 0, 0, 0, dst ); // calculate motion gradient orientation and valid orientation mask - cvCalcMotionGradient( x->mhi, x->mask, x->orient, x->max_time_delta, x->min_time_delta, x->x_mhi_duration ); + cvCalcMotionGradient( x->mhi, x->mask, x->orient, x->max_time_delta, x->min_time_delta, x->x_aperture ); if( !x->storage ) x->storage = cvCreateMemStorage(0); @@ -198,14 +200,13 @@ void pdp_opencv_motempl_update_mhi( t_pdp_opencv_motempl *x, IplImage* img, Ipl cvRound( center.y - magnitude*sin(angle*CV_PI/180))), color, 3, CV_AA, 0 ); - t_atom rlist[6]; - SETFLOAT(&rlist[0], i); - SETFLOAT(&rlist[1], center.x); - SETFLOAT(&rlist[2], center.y); - SETFLOAT(&rlist[3], comp_rect.width); - SETFLOAT(&rlist[4], comp_rect.height); - SETFLOAT(&rlist[5], angle); - outlet_list( x->x_dataout, 0, 6, rlist ); + SETFLOAT(&x->rlist[0], i); + SETFLOAT(&x->rlist[1], center.x); + SETFLOAT(&x->rlist[2], center.y); + SETFLOAT(&x->rlist[3], comp_rect.width); + SETFLOAT(&x->rlist[4], comp_rect.height); + SETFLOAT(&x->rlist[5], angle); + outlet_list( x->x_dataout, 0, 6, x->rlist ); } } @@ -225,23 +226,23 @@ static void pdp_opencv_motempl_process_rgb(t_pdp_opencv_motempl *x) (x->x_height != (t_int)header->info.image.height)) { - post("pdp_opencv_motempl :: resizing plugins"); - - //cv_freeplugins(x); + post("pdp_opencv_motempl :: resizing plugins"); + + //cv_freeplugins(x); - x->x_width = header->info.image.width; - x->x_height = header->info.image.height; - x->x_size = x->x_width*x->x_height; + 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 - cvReleaseImage( &x->image ); - cvReleaseImage( &x->motion ); + //Destroy cv_images + cvReleaseImage( &x->image ); + cvReleaseImage( &x->motion ); - //Create cv_images - x->image = cvCreateImage(cvSize(x->x_width,x->x_height), IPL_DEPTH_8U, 3); - x->motion = cvCreateImage( cvSize(x->image->width,x->image->height), 8, 3 ); - cvZero( x->motion ); - x->motion->origin = x->image->origin; + //create cv_images + x->image = cvCreateImage(cvSize(x->x_width,x->x_height), IPL_DEPTH_8U, 3); + x->motion = cvCreateImage( cvSize(x->image->width,x->image->height), 8, 3 ); + cvZero( x->motion ); + x->motion->origin = x->image->origin; } newheader->info.image.encoding = header->info.image.encoding; @@ -250,52 +251,57 @@ static void pdp_opencv_motempl_process_rgb(t_pdp_opencv_motempl *x) memcpy( newdata, data, x->x_size*3 ); - - // FEM UNA COPIA DEL PACKET A x->grey->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 ); pdp_opencv_motempl_update_mhi( x, x->image, x->motion, x->x_thresh ); memcpy( newdata, x->motion->imageData, x->x_size*3 ); - return; } static void pdp_opencv_motempl_thresh(t_pdp_opencv_motempl *x, t_floatarg f) { - x->x_thresh = (int)f; + x->x_thresh = (int)f; } static void pdp_opencv_motempl_min_size(t_pdp_opencv_motempl *x, t_floatarg f) { - if (f>=0) x->min_size = (int)f; + if (f>=0) x->min_size = (int)f; } static void pdp_opencv_motempl_max_size(t_pdp_opencv_motempl *x, t_floatarg f) { - if (f>=0) x->max_size = (int)f; + if (f>=0) x->max_size = (int)f; } static void pdp_opencv_motempl_mhi_duration(t_pdp_opencv_motempl *x, t_floatarg f) { - if (f>=1) x->x_mhi_duration = (int)f; + if (f>0) x->x_mhi_duration = f; +} + +static void pdp_opencv_motempl_aperture(t_pdp_opencv_motempl *x, t_floatarg f) +{ + if ( ( (int)f == 3.0 ) || ( (int)f == 5.0 ) || ( (int)f == 7.0 ) ) + { + x->x_aperture = (int)f; + } } static void pdp_opencv_motempl_max_time_delta(t_pdp_opencv_motempl *x, t_floatarg f) { - if (f>0) x->max_time_delta = f; + if (f>0) x->max_time_delta = f; } static void pdp_opencv_motempl_min_time_delta(t_pdp_opencv_motempl *x, t_floatarg f) { - if (f>0) x->min_time_delta = f; + if (f>0) x->min_time_delta = f; } static void pdp_opencv_motempl_frame_buffer_num(t_pdp_opencv_motempl *x, t_floatarg f) { - if (f>=3) x->frame_buffer_num = (int)f; - x->buf = NULL; + if (f>=3) x->frame_buffer_num = (int)f; + x->buf = NULL; } static void pdp_opencv_motempl_sendpacket(t_pdp_opencv_motempl *x) @@ -310,34 +316,27 @@ static void pdp_opencv_motempl_sendpacket(t_pdp_opencv_motempl *x) static void pdp_opencv_motempl_process(t_pdp_opencv_motempl *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)){ + int encoding; + t_pdp *header = 0; + + /* check if image data packets are compatible */ + if ( (header = pdp_packet_header(x->x_packet0)) + && (PDP_BITMAP == header->type)){ - /* pdp_opencv_motempl_process inputs and write into active inlet */ - switch(pdp_packet_header(x->x_packet0)->info.image.encoding){ + /* pdp_opencv_motempl_process inputs and write into active inlet */ + switch(pdp_packet_header(x->x_packet0)->info.image.encoding){ - case PDP_BITMAP_RGB: + case PDP_BITMAP_RGB: x->x_packet1 = pdp_packet_clone_rw(x->x_packet0); pdp_queue_add(x, pdp_opencv_motempl_process_rgb, pdp_opencv_motempl_sendpacket, &x->x_queue_id); - break; + break; - default: - /* don't know the type, so dont pdp_opencv_motempl_process */ - break; - - } - } + default: + /* don't know the type, so dont pdp_opencv_motempl_process */ + break; + + } + } } @@ -361,16 +360,14 @@ static void pdp_opencv_motempl_free(t_pdp_opencv_motempl *x) pdp_queue_finish(x->x_queue_id); pdp_packet_mark_unused(x->x_packet0); - //cv_freeplugins(x); - //Destroy cv_images - cvReleaseImage( &x->image ); - cvReleaseImage( &x->motion ); + //Destroy cv_images + cvReleaseImage( &x->image ); + cvReleaseImage( &x->motion ); } t_class *pdp_opencv_motempl_class; - void *pdp_opencv_motempl_new(t_floatarg f) { int i; @@ -395,7 +392,8 @@ void *pdp_opencv_motempl_new(t_floatarg f) x->x_thresh = 30; x->x_mhi_duration = 1; - + x->x_aperture = 3; + x->last = 0; // various tracking parameters (in seconds) x->max_time_delta = 0.5; @@ -414,7 +412,6 @@ void *pdp_opencv_motempl_new(t_floatarg f) x->storage = NULL; - return (void *)x; } @@ -428,13 +425,14 @@ extern "C" void pdp_opencv_motempl_setup(void) { - post( " pdp_opencv_motempl"); + post( " pdp_opencv_motempl"); pdp_opencv_motempl_class = class_new(gensym("pdp_opencv_motempl"), (t_newmethod)pdp_opencv_motempl_new, - (t_method)pdp_opencv_motempl_free, sizeof(t_pdp_opencv_motempl), 0, A_DEFFLOAT, A_NULL); + (t_method)pdp_opencv_motempl_free, sizeof(t_pdp_opencv_motempl), 0, A_DEFFLOAT, A_NULL); class_addmethod(pdp_opencv_motempl_class, (t_method)pdp_opencv_motempl_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL); class_addmethod(pdp_opencv_motempl_class, (t_method)pdp_opencv_motempl_thresh, gensym("threshold"), A_FLOAT, A_NULL ); class_addmethod(pdp_opencv_motempl_class, (t_method)pdp_opencv_motempl_mhi_duration, gensym("mhi_duration"), A_FLOAT, A_NULL ); + class_addmethod(pdp_opencv_motempl_class, (t_method)pdp_opencv_motempl_aperture, gensym("aperture"), A_FLOAT, A_NULL ); class_addmethod(pdp_opencv_motempl_class, (t_method)pdp_opencv_motempl_max_time_delta, gensym("max_time_delta"), A_FLOAT, A_NULL ); class_addmethod(pdp_opencv_motempl_class, (t_method)pdp_opencv_motempl_min_time_delta, gensym("min_time_delta"), A_FLOAT, A_NULL ); class_addmethod(pdp_opencv_motempl_class, (t_method)pdp_opencv_motempl_frame_buffer_num, gensym("frame_buffer_num"), A_FLOAT, A_NULL ); |