From f29ff03b88ab33d418c575a28447d65167d054bb Mon Sep 17 00:00:00 2001 From: "N.N." Date: Sun, 30 Aug 2009 19:07:04 +0000 Subject: fixed mouse pointing ( almost ) svn path=/trunk/externals/pix_opencv/; revision=12146 --- pix_opencv_floodfill-help.pd | 159 +++++++++++++++++++------------------ pix_opencv_floodfill.cc | 38 ++++++--- pix_opencv_lk-help.pd | 182 +++++++++++++++++++++++-------------------- pix_opencv_lk.cc | 39 ++++++++-- pix_opencv_lk.h | 2 +- 5 files changed, 239 insertions(+), 181 deletions(-) diff --git a/pix_opencv_floodfill-help.pd b/pix_opencv_floodfill-help.pd index 740b1b1..356ce1c 100755 --- a/pix_opencv_floodfill-help.pd +++ b/pix_opencv_floodfill-help.pd @@ -1,42 +1,52 @@ -#N canvas 5 105 1192 685 10; +#N canvas 248 107 1192 685 10; #X obj 396 -37 gemhead; #X obj 212 501 pix_texture; -#X obj 212 529 square 2; #X obj 28 132 cnv 15 220 70 empty empty empty 20 12 0 14 -195568 -66577 0; #N canvas 0 22 454 304 gemwin 0; -#X obj 132 136 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 132 112 create \, 1; -#X msg 238 112 destroy; #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 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 268 69 pd Gem.init; +#X obj 162 241 gemwin; +#X msg 161 188 create \, 1; +#X msg 237 189 destroy; +#X msg 188 161 dimen 320 240; +#X msg 283 161 frame 15; +#X obj 164 126 t b b b; #X connect 1 0 2 0; -#X restore 289 80 pd Gem.init; #X connect 2 0 3 0; -#X connect 3 0 4 0; -#X connect 3 0 6 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 8 0 0 0; +#X connect 2 0 11 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 6 0; +#X connect 11 0 7 0; +#X connect 11 1 9 0; +#X connect 11 2 10 0; #X restore 35 178 pd gemwin; -#X msg 35 154 create; +#X msg 36 156 destroy; #X text 36 136 Create window and render; -#X obj 213 404 pix_texture; -#X obj 213 432 square 2; -#X obj 325 71 translateXYZ -2 0 0; -#X obj 326 100 separator; #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 @@ -52,9 +62,8 @@ #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 0 1 +#X obj 517 8 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 1 1 ; -#X obj 326 126 translateXYZ 4 0 0; #X obj 580 26 loadbang; #X msg 528 50 colorspace RGBA; #X obj 771 5 gemmouse; @@ -103,54 +112,52 @@ specific color; #X text 643 453 detected components; #X msg 437 307 connectivity 4; #X msg 439 330 connectivity 8; -#X connect 0 0 21 0; -#X connect 1 0 2 0; -#X connect 4 0 5 0; -#X connect 5 0 4 0; -#X connect 7 0 8 0; -#X connect 9 0 7 0; -#X connect 9 0 10 0; -#X connect 10 0 24 0; -#X connect 12 0 19 0; -#X connect 13 0 14 0; -#X connect 13 1 15 0; -#X connect 13 2 16 0; -#X connect 17 0 18 0; -#X connect 18 0 21 1; +#X obj 211 525 pix_resize 320 240; +#X obj 212 555 rectangle 4 3; +#X connect 0 0 16 0; +#X connect 1 0 64 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 28 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 21 0; -#X connect 21 0 9 0; -#X connect 21 1 13 0; -#X connect 21 2 17 0; -#X connect 22 0 21 0; -#X connect 23 0 22 0; -#X connect 24 0 34 0; -#X connect 25 0 26 0; -#X connect 26 0 21 0; -#X connect 27 0 29 1; -#X connect 27 1 28 1; -#X connect 27 2 32 0; -#X connect 28 0 31 1; -#X connect 29 0 31 0; -#X connect 30 0 29 0; -#X connect 30 1 28 0; -#X connect 31 0 41 0; -#X connect 32 0 33 0; -#X connect 33 0 30 0; -#X connect 34 0 1 0; -#X connect 34 1 57 0; -#X connect 39 0 34 1; -#X connect 40 0 34 2; -#X connect 41 0 34 0; -#X connect 42 0 34 0; -#X connect 43 0 42 0; -#X connect 45 0 34 0; -#X connect 50 0 34 0; -#X connect 51 0 34 0; -#X connect 57 0 62 0; -#X connect 62 0 58 0; -#X connect 62 1 59 0; -#X connect 62 2 60 0; -#X connect 62 3 61 0; -#X connect 68 0 34 0; -#X connect 69 0 34 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 23 0 25 0; +#X connect 24 0 23 0; +#X connect 24 1 22 0; +#X connect 25 0 35 0; +#X connect 26 0 27 0; +#X connect 27 0 24 0; +#X connect 28 0 1 0; +#X connect 28 1 51 0; +#X connect 33 0 28 1; +#X connect 34 0 28 2; +#X connect 35 0 28 0; +#X connect 36 0 28 0; +#X connect 37 0 36 0; +#X connect 39 0 28 0; +#X connect 44 0 28 0; +#X connect 45 0 28 0; +#X connect 51 0 56 0; +#X connect 56 0 52 0; +#X connect 56 1 53 0; +#X connect 56 2 54 0; +#X connect 56 3 55 0; +#X connect 62 0 28 0; +#X connect 63 0 28 0; +#X connect 64 0 65 0; diff --git a/pix_opencv_floodfill.cc b/pix_opencv_floodfill.cc index 3b492c2..1c8cdd3 100755 --- a/pix_opencv_floodfill.cc +++ b/pix_opencv_floodfill.cc @@ -90,17 +90,18 @@ void pix_opencv_floodfill :: processRGBAImage(imageStruct &image) this->comp_xsize=image.xsize; this->comp_ysize=image.ysize; + cvReleaseImage( &rgba ); + cvReleaseImage( &rgb ); + cvReleaseImage( &grey ); + rgba = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 4 ); rgb = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 3 ); grey = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 1 ); } memcpy( rgba->imageData, image.data, image.xsize*image.ysize*4 ); - - if ( !x_color ) - { - cvCvtColor(rgba, grey, CV_BGRA2GRAY); - } + cvCvtColor(rgba, grey, CV_BGRA2GRAY); + cvCvtColor(rgba, rgb, CV_BGRA2BGR); // mark recognized components for ( i=0; iimageData, image.xsize*image.ysize*4 ); } @@ -152,6 +157,10 @@ void pix_opencv_floodfill :: processRGBImage(imageStruct &image) this->comp_xsize=image.xsize; this->comp_ysize=image.ysize; + cvReleaseImage( &rgba ); + cvReleaseImage( &rgb ); + cvReleaseImage( &grey ); + rgba = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 4 ); rgb = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 3 ); grey = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 1 ); @@ -219,6 +228,10 @@ void pix_opencv_floodfill :: processGrayImage(imageStruct &image) this->comp_xsize=image.xsize; this->comp_ysize=image.ysize; + cvReleaseImage( &rgba ); + cvReleaseImage( &rgb ); + cvReleaseImage( &grey ); + rgba = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 4 ); rgb = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 3 ); grey = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 1 ); @@ -287,9 +300,9 @@ void pix_opencv_floodfill :: connectivityMessCallback(void *data, t_floatarg co GetMyClass(data)->connectivityMess(connectivity); } -void pix_opencv_floodfill :: markMessCallback(void *data, t_floatarg perx, t_floatarg pery) +void pix_opencv_floodfill :: markMessCallback(void *data, t_floatarg px, t_floatarg py) { - GetMyClass(data)->markMess(perx, pery); + GetMyClass(data)->markMess(px, py); } void pix_opencv_floodfill :: deleteMessCallback(void *data, t_floatarg index) @@ -354,19 +367,19 @@ void pix_opencv_floodfill :: connectivityMess(float connectivity) x_connectivity = (int)connectivity; } -void pix_opencv_floodfill :: markMess(float fperx, float fpery) +void pix_opencv_floodfill :: markMess(float fpx, float fpy) { int i; int inserted; int px, py; - if ( ( fperx < 0.0 ) || ( fperx > 1.0 ) || ( fpery < 0.0 ) || ( fpery > 1.0 ) ) + if ( ( fpx < 0.0 ) || ( fpx > comp_xsize ) || ( fpy < 0.0 ) || ( fpy > comp_ysize ) ) { return; } - px = (int)(fperx*comp_xsize); - py = (int)(fpery*comp_ysize); + px = (int)fpx; + py = comp_ysize-(int)fpy; inserted = 0; for ( i=0; icomp_xsize=image.xsize; this->comp_ysize=image.ysize; + cvReleaseImage( &rgba ); + cvReleaseImage( &rgb ); + cvReleaseImage( &grey ); + cvReleaseImage( &prev_grey ); + cvReleaseImage( &pyramid ); + cvReleaseImage( &prev_pyramid ); + rgba = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 4 ); rgb = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 3 ); grey = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 1 ); @@ -238,13 +245,14 @@ void pix_opencv_lk :: processRGBAImage(imageStruct &image) // first marking if ( x_xmark[im] != -1.0 ) { - if ( ( abs( points[1][i].x - x_xmark[im] ) <= maxmove ) && ( abs( points[1][i].y - x_ymark[im] ) <= maxmove ) ) + // post( "pix_opencv_lk : compare (%f,%f) to (%d,%d)", points[1][i].x, points[1][i].y, x_xmark[im], x_ymark[im] ); + if ( ( abs( (int)points[1][i].x - x_xmark[im] ) <= maxmove ) && ( abs( (int)points[1][i].y - x_ymark[im] ) <= maxmove ) ) { char tindex[4]; sprintf( tindex, "%d", im+1 ); cvPutText( rgba, tindex, cvPointFrom32f(points[1][i]), &font, CV_RGB(255,255,255)); - x_xmark[im]=points[1][i].x; - x_ymark[im]=points[1][i].y; + x_xmark[im]=(int)points[1][i].x; + x_ymark[im]=(int)points[1][i].y; x_found[im]=ftolerance; marked=1; SETFLOAT(&x_list[0], im+1); @@ -359,6 +367,13 @@ void pix_opencv_lk :: processRGBImage(imageStruct &image) this->comp_xsize=image.xsize; this->comp_ysize=image.ysize; + cvReleaseImage( &rgba ); + cvReleaseImage( &rgb ); + cvReleaseImage( &grey ); + cvReleaseImage( &prev_grey ); + cvReleaseImage( &pyramid ); + cvReleaseImage( &prev_pyramid ); + rgba = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 4 ); rgb = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 3 ); grey = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 1 ); @@ -614,6 +629,13 @@ void pix_opencv_lk :: processGrayImage(imageStruct &image) this->comp_xsize=image.xsize; this->comp_ysize=image.ysize; + cvReleaseImage( &rgba ); + cvReleaseImage( &rgb ); + cvReleaseImage( &grey ); + cvReleaseImage( &prev_grey ); + cvReleaseImage( &pyramid ); + cvReleaseImage( &prev_pyramid ); + rgba = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 4 ); rgb = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 3 ); grey = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 1 ); @@ -992,17 +1014,17 @@ void pix_opencv_lk :: markMess(int argc, t_atom *argv) } else { - float fperx = argv[0].a_w.w_float; - float fpery = argv[1].a_w.w_float; + float fpx = argv[0].a_w.w_float; + float fpy = argv[1].a_w.w_float; int px, py; - if ( ( fperx < 0.0 ) || ( fperx > 1.0 ) || ( fpery < 0.0 ) || ( fpery > 1.0 ) ) + if ( ( fpx < 0.0 ) || ( fpx > comp_xsize ) || ( fpy < 0.0 ) || ( fpy > comp_ysize ) ) { return; } - px = (int)(fperx*comp_xsize); - py = (int)(fpery*comp_ysize); + px = (int)fpx; + py = comp_ysize-(int)fpy; inserted = 0; for ( i=0; i