diff options
-rwxr-xr-x | pix_opencv_camshift-help.pd | 17 | ||||
-rw-r--r-- | pix_opencv_contours_boundingrect-help.pd | 4 | ||||
-rwxr-xr-x | pix_opencv_floodfill-help.pd | 33 | ||||
-rwxr-xr-x | pix_opencv_lk-help.pd | 39 | ||||
-rwxr-xr-x | pix_opencv_lk.cc | 169 | ||||
-rwxr-xr-x | pix_opencv_lk.h | 4 | ||||
-rwxr-xr-x | pix_opencv_surf-help.pd | 17 | ||||
-rwxr-xr-x | pix_opencv_surf.cc | 5 | ||||
-rwxr-xr-x | pix_opencv_surf.h | 2 |
9 files changed, 149 insertions, 141 deletions
diff --git a/pix_opencv_camshift-help.pd b/pix_opencv_camshift-help.pd index eb89ecd..123a53d 100755 --- a/pix_opencv_camshift-help.pd +++ b/pix_opencv_camshift-help.pd @@ -1,4 +1,4 @@ -#N canvas 392 94 1192 685 10; +#N canvas 248 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 @@ -17,19 +17,16 @@ #X msg 62 93 reset; #X obj 49 135 outlet; #X msg 107 89 dimen 320 240; -#X msg 202 89 frame 5; #X obj 107 51 t b b b; -#X connect 0 0 5 0; +#X connect 0 0 4 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 connect 4 0 3 0; +#X connect 4 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 msg 247 137 frame 5; #X connect 2 0 3 0; #X connect 3 0 4 0; #X connect 3 0 9 0; @@ -46,7 +43,7 @@ #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 text 38 139 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 @@ -62,7 +59,7 @@ #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 517 8 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1 ; #X obj 580 26 loadbang; #X msg 531 52 colorspace RGBA; diff --git a/pix_opencv_contours_boundingrect-help.pd b/pix_opencv_contours_boundingrect-help.pd index bb9d32d..8bcf374 100644 --- a/pix_opencv_contours_boundingrect-help.pd +++ b/pix_opencv_contours_boundingrect-help.pd @@ -20,7 +20,7 @@ #X obj 161 230 gemwin; #X msg 160 177 create \, 1; #X msg 236 178 destroy; -#X msg 282 150 frame 5; +#X msg 294 178 frame 5; #X obj 163 140 t b b b; #X connect 1 0 2 0; #X connect 2 0 3 0; @@ -38,7 +38,7 @@ #X msg 30 456 destroy; #X text 26 436 Create window and render; #X obj 200 368 pix_texture; -#X obj 200 396 square 2; +#X obj 198 397 square 2; #X obj 266 167 translateXYZ -2 0 0; #X obj 281 199 separator; #X obj 344 246 cnv 15 550 250 empty empty empty 20 12 0 14 -24198 -66577 diff --git a/pix_opencv_floodfill-help.pd b/pix_opencv_floodfill-help.pd index e6aca60..d3326c9 100755 --- a/pix_opencv_floodfill-help.pd +++ b/pix_opencv_floodfill-help.pd @@ -14,25 +14,22 @@ #X msg 62 93 reset; #X obj 49 135 outlet; #X msg 107 89 dimen 320 240; -#X msg 202 89 frame 5; #X obj 107 51 t b b b; -#X connect 0 0 5 0; +#X connect 0 0 4 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 connect 4 0 3 0; +#X connect 4 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 msg 279 161 frame 5; #X connect 1 0 2 0; #X connect 2 0 3 0; -#X connect 2 0 11 0; +#X connect 2 0 10 0; #X connect 2 1 4 0; #X connect 2 1 8 0; #X connect 3 0 0 0; @@ -40,13 +37,13 @@ #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 connect 10 0 7 0; +#X connect 10 1 9 0; +#X connect 10 2 11 0; +#X connect 11 0 6 0; #X restore 35 178 pd gemwin; #X msg 36 156 destroy; -#X text 36 136 Create window and render; +#X text 36 135 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 @@ -72,11 +69,11 @@ #X obj 868 50 route 1; #X msg 889 75 bang; #X obj 367 424 pix_opencv_floodfill; -#X text -38 44 used in tracking algorithms as an object selector; -#X text -38 71 and Yves Degoyon ( ydegoyon@gmail.com ); -#X text -39 21 pdp_opencv_floodfill : mark image components with a -specific color; -#X text -38 57 Written by Lluis Gomez i Bigorda ( lluisgomez@hangar.org +#X text 56 60 used in tracking algorithms as an object selector; +#X text 56 87 and Yves Degoyon ( ydegoyon@gmail.com ); +#X text 55 37 pdp_opencv_floodfill : mark image components with a specific +color; +#X text 56 73 Written by Lluis Gomez i Bigorda ( lluisgomez@hangar.org ); #X floatatom 458 376 5 0 0 0 - - -; #X floatatom 466 397 5 0 0 0 - - -; diff --git a/pix_opencv_lk-help.pd b/pix_opencv_lk-help.pd index 6a6aa78..63b885b 100755 --- a/pix_opencv_lk-help.pd +++ b/pix_opencv_lk-help.pd @@ -1,6 +1,6 @@ #N canvas 248 90 1192 685 10; #X obj 396 -37 gemhead; -#X obj 218 457 pix_texture; +#X obj 212 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; @@ -17,19 +17,16 @@ #X msg 62 93 reset; #X obj 49 135 outlet; #X msg 107 89 dimen 320 240; -#X msg 202 89 frame 5; #X obj 107 51 t b b b; -#X connect 0 0 5 0; +#X connect 0 0 4 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 connect 4 0 3 0; +#X connect 4 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 msg 250 137 frame 5; #X connect 2 0 3 0; #X connect 3 0 4 0; #X connect 3 0 9 0; @@ -45,7 +42,7 @@ #X connect 10 0 0 0; #X connect 11 0 0 0; #X restore 35 178 pd gemwin; -#X msg 35 157 create; +#X msg 35 157 destroy; #X text 36 136 Create window and render; #X obj 340 180 cnv 15 600 450 empty empty empty 20 12 0 14 -24198 -66577 0; @@ -62,7 +59,7 @@ #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 floatatom 488 520 5 0 0 0 - - -; #X text 523 519 window size; @@ -117,7 +114,6 @@ #X text 651 466 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 msg 552 478 pdelaunay 1 50; #X msg 533 409 ftolerance \$1; #X floatatom 625 409 5 0 0 0 - - -; #X text 665 409 frame tolerance for point identification ( default @@ -131,14 +127,15 @@ -1 -1 0; #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 518 rectangle 4 3; #X obj 212 489 pix_resize 320 240; #X obj 588 13 loadbang; #X msg 588 38 colorspace RGBA; #X msg 692 38 colorspace RGB; #X msg 651 12 colorspace Grey; +#X msg 550 475 pdelaunay 1 500; #X connect 0 0 16 0; -#X connect 1 0 79 0; +#X connect 1 0 78 0; #X connect 3 0 4 0; #X connect 4 0 3 0; #X connect 7 0 14 0; @@ -180,9 +177,9 @@ #X connect 52 1 53 1; #X connect 52 2 58 0; #X connect 53 0 56 1; -#X connect 53 0 77 0; +#X connect 53 0 76 0; #X connect 54 0 56 0; -#X connect 54 0 76 0; +#X connect 54 0 75 0; #X connect 55 0 54 0; #X connect 55 1 53 0; #X connect 56 0 33 0; @@ -193,11 +190,11 @@ #X connect 65 0 51 0; #X connect 66 0 51 0; #X connect 68 0 51 0; -#X connect 69 0 51 0; -#X connect 70 0 69 0; -#X connect 75 0 34 0; -#X connect 79 0 78 0; -#X connect 80 0 81 0; +#X connect 69 0 68 0; +#X connect 74 0 34 0; +#X connect 78 0 77 0; +#X connect 79 0 80 0; +#X connect 80 0 16 0; #X connect 81 0 16 0; #X connect 82 0 16 0; -#X connect 83 0 16 0; +#X connect 83 0 51 0; diff --git a/pix_opencv_lk.cc b/pix_opencv_lk.cc index 7de183a..fd90d15 100755 --- a/pix_opencv_lk.cc +++ b/pix_opencv_lk.cc @@ -67,9 +67,11 @@ pix_opencv_lk :: pix_opencv_lk() cvInitFont( &font, CV_FONT_HERSHEY_PLAIN, 1.0, 1.0, 0, 1, 8 ); rgba = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 4 ); + orgb = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 3 ); rgb = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 3 ); - grey = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 1 ); - prev_grey = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 1 ); + gray = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 1 ); + ogray = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 1 ); + prev_gray = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 1 ); pyramid = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 1 ); prev_pyramid = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 1 ); points[0] = (CvPoint2D32f*)cvAlloc(MAX_COUNT*sizeof(points[0][0])); @@ -86,9 +88,11 @@ pix_opencv_lk :: ~pix_opencv_lk() { // Destroy cv_images cvReleaseImage( &rgba ); + cvReleaseImage( &orgb ); cvReleaseImage( &rgb ); - cvReleaseImage( &grey ); - cvReleaseImage( &prev_grey ); + cvReleaseImage( &gray ); + cvReleaseImage( &ogray ); + cvReleaseImage( &prev_gray ); cvReleaseImage( &pyramid ); cvReleaseImage( &prev_pyramid ); } @@ -110,16 +114,20 @@ void pix_opencv_lk :: processRGBAImage(imageStruct &image) this->comp_ysize=image.ysize; cvReleaseImage( &rgba ); + cvReleaseImage( &orgb ); cvReleaseImage( &rgb ); - cvReleaseImage( &grey ); - cvReleaseImage( &prev_grey ); + cvReleaseImage( &gray ); + cvReleaseImage( &ogray ); + cvReleaseImage( &prev_gray ); cvReleaseImage( &pyramid ); cvReleaseImage( &prev_pyramid ); rgba = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 4 ); + orgb = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 3 ); rgb = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 3 ); - grey = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 1 ); - prev_grey = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 1 ); + gray = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 1 ); + ogray = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 1 ); + prev_gray = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 1 ); pyramid = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 1 ); prev_pyramid = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 1 ); points[0] = (CvPoint2D32f*)cvAlloc(MAX_COUNT*sizeof(points[0][0])); @@ -130,7 +138,8 @@ void pix_opencv_lk :: processRGBAImage(imageStruct &image) memcpy( rgba->imageData, image.data, image.xsize*image.ysize*4 ); cvCvtColor(rgba, rgb, CV_BGRA2RGB); - cvCvtColor(rgba, grey, CV_BGRA2GRAY); + cvCvtColor(rgba, orgb, CV_BGRA2RGB); + cvCvtColor(rgba, gray, CV_BGRA2GRAY); if( night_mode ) cvZero( rgb ); @@ -159,13 +168,13 @@ void pix_opencv_lk :: processRGBAImage(imageStruct &image) if( need_to_init ) { /* automatic initialization */ - IplImage* eig = cvCreateImage( cvSize(grey->width,grey->height), 32, 1 ); - IplImage* temp = cvCreateImage( cvSize(grey->width,grey->height), 32, 1 ); + IplImage* eig = cvCreateImage( cvSize(gray->width,gray->height), 32, 1 ); + IplImage* temp = cvCreateImage( cvSize(gray->width,gray->height), 32, 1 ); count = MAX_COUNT; - cvGoodFeaturesToTrack( grey, eig, temp, points[1], &count, + cvGoodFeaturesToTrack( gray, eig, temp, points[1], &count, quality, min_distance, 0, 3, 0, 0.04 ); - cvFindCornerSubPix( grey, points[1], count, + cvFindCornerSubPix( gray, points[1], count, cvSize(win_size,win_size), cvSize(-1,-1), cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,20,0.03)); cvReleaseImage( &eig ); @@ -175,7 +184,7 @@ void pix_opencv_lk :: processRGBAImage(imageStruct &image) } else if( count > 0 ) { - cvCalcOpticalFlowPyrLK( prev_grey, grey, prev_pyramid, pyramid, + cvCalcOpticalFlowPyrLK( prev_gray, gray, prev_pyramid, pyramid, points[0], points[1], count, cvSize(win_size,win_size), 3, status, 0, cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,20,0.03), flags ); flags |= CV_LKFLOW_PYR_A_READY; @@ -217,17 +226,17 @@ void pix_opencv_lk :: processRGBAImage(imageStruct &image) if ( ( ppx < 0 ) || ( ppx >= comp_xsize ) ) continue; if ( ( ppy < 0 ) || ( ppy >= comp_ysize ) ) continue; - uchar red = ((uchar*)(rgba->imageData + rgba->widthStep*ppx))[ppy*4]; - uchar green = ((uchar*)(rgba->imageData + rgba->widthStep*ppx))[ppy*4+1]; - uchar blue = ((uchar*)(rgba->imageData + rgba->widthStep*ppx))[ppy*4+2]; + uchar red = ((uchar*)(orgb->imageData + orgb->widthStep*ppx))[ppy*3]; + uchar green = ((uchar*)(orgb->imageData + orgb->widthStep*ppx))[ppy*3+1]; + uchar blue = ((uchar*)(orgb->imageData + orgb->widthStep*ppx))[ppy*3+2]; - uchar pred = ((uchar*)(rgba->imageData + rgba->widthStep*x_xmark[delaunay-1]))[x_ymark[delaunay-1]*4]; - uchar pgreen = ((uchar*)(rgba->imageData + rgba->widthStep*x_xmark[delaunay-1]))[x_ymark[delaunay-1]*4+1]; - uchar pblue = ((uchar*)(rgba->imageData + rgba->widthStep*x_xmark[delaunay-1]))[x_ymark[delaunay-1]*4+2]; + uchar pred = ((uchar*)(orgb->imageData + orgb->widthStep*x_xmark[delaunay-1]))[x_ymark[delaunay-1]*3]; + uchar pgreen = ((uchar*)(orgb->imageData + orgb->widthStep*x_xmark[delaunay-1]))[x_ymark[delaunay-1]*3+1]; + uchar pblue = ((uchar*)(orgb->imageData + orgb->widthStep*x_xmark[delaunay-1]))[x_ymark[delaunay-1]*3+2]; int diff = abs(red-pred) + abs(green-pgreen) + abs(blue-pblue); - // post( "pix_opencv_lk : point (%d,%d,%d) : diff : %d", blue, green, red, diff ); + // post( "pix_opencv_lk : point (%d,%d,%d) : diff : %d threshold : %d", blue, green, red, diff, threshold ); if ( diff < threshold ) { @@ -299,7 +308,7 @@ void pix_opencv_lk :: processRGBAImage(imageStruct &image) if( add_remove_pt && count < MAX_COUNT ) { points[1][count++] = cvPointTo32f(pt); - cvFindCornerSubPix( grey, points[1] + count - 1, 1, + cvFindCornerSubPix( gray, points[1] + count - 1, 1, cvSize(win_size,win_size), cvSize(-1,-1), cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,20,0.03)); add_remove_pt = 0; @@ -348,7 +357,7 @@ void pix_opencv_lk :: processRGBAImage(imageStruct &image) } } - CV_SWAP( prev_grey, grey, swap_temp ); + CV_SWAP( prev_gray, gray, swap_temp ); CV_SWAP( prev_pyramid, pyramid, swap_temp ); CV_SWAP( points[0], points[1], swap_points ); need_to_init = 0; @@ -370,16 +379,20 @@ void pix_opencv_lk :: processRGBImage(imageStruct &image) this->comp_ysize=image.ysize; cvReleaseImage( &rgba ); + cvReleaseImage( &orgb ); cvReleaseImage( &rgb ); - cvReleaseImage( &grey ); - cvReleaseImage( &prev_grey ); + cvReleaseImage( &gray ); + cvReleaseImage( &ogray ); + cvReleaseImage( &prev_gray ); cvReleaseImage( &pyramid ); cvReleaseImage( &prev_pyramid ); rgba = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 4 ); + orgb = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 3 ); rgb = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 3 ); - grey = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 1 ); - prev_grey = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 1 ); + gray = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 1 ); + ogray = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 1 ); + prev_gray = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 1 ); pyramid = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 1 ); prev_pyramid = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 1 ); points[0] = (CvPoint2D32f*)cvAlloc(MAX_COUNT*sizeof(points[0][0])); @@ -389,7 +402,8 @@ void pix_opencv_lk :: processRGBImage(imageStruct &image) } memcpy( rgb->imageData, image.data, image.xsize*image.ysize*3 ); - cvCvtColor(rgb, grey, CV_BGRA2GRAY); + memcpy( orgb->imageData, image.data, image.xsize*image.ysize*3 ); + cvCvtColor(rgb, gray, CV_BGRA2GRAY); if( night_mode ) cvZero( rgb ); @@ -418,13 +432,13 @@ void pix_opencv_lk :: processRGBImage(imageStruct &image) if( need_to_init ) { /* automatic initialization */ - IplImage* eig = cvCreateImage( cvSize(grey->width,grey->height), 32, 1 ); - IplImage* temp = cvCreateImage( cvSize(grey->width,grey->height), 32, 1 ); + IplImage* eig = cvCreateImage( cvSize(gray->width,gray->height), 32, 1 ); + IplImage* temp = cvCreateImage( cvSize(gray->width,gray->height), 32, 1 ); count = MAX_COUNT; - cvGoodFeaturesToTrack( grey, eig, temp, points[1], &count, + cvGoodFeaturesToTrack( gray, eig, temp, points[1], &count, quality, min_distance, 0, 3, 0, 0.04 ); - cvFindCornerSubPix( grey, points[1], count, + cvFindCornerSubPix( gray, points[1], count, cvSize(win_size,win_size), cvSize(-1,-1), cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,20,0.03)); cvReleaseImage( &eig ); @@ -434,7 +448,7 @@ void pix_opencv_lk :: processRGBImage(imageStruct &image) } else if( count > 0 ) { - cvCalcOpticalFlowPyrLK( prev_grey, grey, prev_pyramid, pyramid, + cvCalcOpticalFlowPyrLK( prev_gray, gray, prev_pyramid, pyramid, points[0], points[1], count, cvSize(win_size,win_size), 3, status, 0, cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,20,0.03), flags ); flags |= CV_LKFLOW_PYR_A_READY; @@ -476,13 +490,13 @@ void pix_opencv_lk :: processRGBImage(imageStruct &image) if ( ( ppx < 0 ) || ( ppx >= comp_xsize ) ) continue; if ( ( ppy < 0 ) || ( ppy >= comp_ysize ) ) continue; - uchar red = ((uchar*)(rgb->imageData + rgb->widthStep*ppx))[ppy*3]; - uchar green = ((uchar*)(rgb->imageData + rgb->widthStep*ppx))[ppy*3+1]; - uchar blue = ((uchar*)(rgb->imageData + rgb->widthStep*ppx))[ppy*3+2]; + uchar red = ((uchar*)(orgb->imageData + orgb->widthStep*ppx))[ppy*3]; + uchar green = ((uchar*)(orgb->imageData + orgb->widthStep*ppx))[ppy*3+1]; + uchar blue = ((uchar*)(orgb->imageData + orgb->widthStep*ppx))[ppy*3+2]; - uchar pred = ((uchar*)(rgb->imageData + rgb->widthStep*x_xmark[delaunay-1]))[x_ymark[delaunay-1]*3]; - uchar pgreen = ((uchar*)(rgb->imageData + rgb->widthStep*x_xmark[delaunay-1]))[x_ymark[delaunay-1]*3+1]; - uchar pblue = ((uchar*)(rgb->imageData + rgb->widthStep*x_xmark[delaunay-1]))[x_ymark[delaunay-1]*3+2]; + uchar pred = ((uchar*)(orgb->imageData + orgb->widthStep*x_xmark[delaunay-1]))[x_ymark[delaunay-1]*3]; + uchar pgreen = ((uchar*)(orgb->imageData + orgb->widthStep*x_xmark[delaunay-1]))[x_ymark[delaunay-1]*3+1]; + uchar pblue = ((uchar*)(orgb->imageData + orgb->widthStep*x_xmark[delaunay-1]))[x_ymark[delaunay-1]*3+2]; int diff = abs(red-pred) + abs(green-pgreen) + abs(blue-pblue); @@ -557,7 +571,7 @@ void pix_opencv_lk :: processRGBImage(imageStruct &image) if( add_remove_pt && count < MAX_COUNT ) { points[1][count++] = cvPointTo32f(pt); - cvFindCornerSubPix( grey, points[1] + count - 1, 1, + cvFindCornerSubPix( gray, points[1] + count - 1, 1, cvSize(win_size,win_size), cvSize(-1,-1), cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,20,0.03)); add_remove_pt = 0; @@ -606,7 +620,7 @@ void pix_opencv_lk :: processRGBImage(imageStruct &image) } } - CV_SWAP( prev_grey, grey, swap_temp ); + CV_SWAP( prev_gray, gray, swap_temp ); CV_SWAP( prev_pyramid, pyramid, swap_temp ); CV_SWAP( points[0], points[1], swap_points ); need_to_init = 0; @@ -632,16 +646,19 @@ void pix_opencv_lk :: processGrayImage(imageStruct &image) this->comp_ysize=image.ysize; cvReleaseImage( &rgba ); + cvReleaseImage( &orgb ); cvReleaseImage( &rgb ); - cvReleaseImage( &grey ); - cvReleaseImage( &prev_grey ); + cvReleaseImage( &ogray ); + cvReleaseImage( &gray ); + cvReleaseImage( &prev_gray ); cvReleaseImage( &pyramid ); cvReleaseImage( &prev_pyramid ); rgba = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 4 ); + orgb = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 3 ); rgb = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 3 ); - grey = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 1 ); - prev_grey = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 1 ); + gray = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 1 ); + prev_gray = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 1 ); pyramid = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 1 ); prev_pyramid = cvCreateImage( cvSize(comp_xsize, comp_ysize), 8, 1 ); points[0] = (CvPoint2D32f*)cvAlloc(MAX_COUNT*sizeof(points[0][0])); @@ -650,10 +667,11 @@ void pix_opencv_lk :: processGrayImage(imageStruct &image) } - memcpy( grey->imageData, image.data, image.xsize*image.ysize ); + memcpy( gray->imageData, image.data, image.xsize*image.ysize ); + memcpy( ogray->imageData, image.data, image.xsize*image.ysize ); if( night_mode ) - cvZero( grey ); + cvZero( gray ); for ( im=0; im<MAX_MARKERS; im++ ) { @@ -679,13 +697,13 @@ void pix_opencv_lk :: processGrayImage(imageStruct &image) if( need_to_init ) { /* automatic initialization */ - IplImage* eig = cvCreateImage( cvSize(grey->width,grey->height), 32, 1 ); - IplImage* temp = cvCreateImage( cvSize(grey->width,grey->height), 32, 1 ); + IplImage* eig = cvCreateImage( cvSize(gray->width,gray->height), 32, 1 ); + IplImage* temp = cvCreateImage( cvSize(gray->width,gray->height), 32, 1 ); count = MAX_COUNT; - cvGoodFeaturesToTrack( grey, eig, temp, points[1], &count, + cvGoodFeaturesToTrack( gray, eig, temp, points[1], &count, quality, min_distance, 0, 3, 0, 0.04 ); - cvFindCornerSubPix( grey, points[1], count, + cvFindCornerSubPix( gray, points[1], count, cvSize(win_size,win_size), cvSize(-1,-1), cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,20,0.03)); cvReleaseImage( &eig ); @@ -695,7 +713,7 @@ void pix_opencv_lk :: processGrayImage(imageStruct &image) } else if( count > 0 ) { - cvCalcOpticalFlowPyrLK( prev_grey, grey, prev_pyramid, pyramid, + cvCalcOpticalFlowPyrLK( prev_gray, gray, prev_pyramid, pyramid, points[0], points[1], count, cvSize(win_size,win_size), 3, status, 0, cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,20,0.03), flags ); flags |= CV_LKFLOW_PYR_A_READY; @@ -737,8 +755,8 @@ void pix_opencv_lk :: processGrayImage(imageStruct &image) if ( ( ppx < 0 ) || ( ppx >= comp_xsize ) ) continue; if ( ( ppy < 0 ) || ( ppy >= comp_ysize ) ) continue; - uchar lum = ((uchar*)(grey->imageData + grey->widthStep*ppx))[ppy]; - uchar plum = ((uchar*)(grey->imageData + grey->widthStep*x_xmark[delaunay-1]))[x_ymark[delaunay-1]]; + uchar lum = ((uchar*)(ogray->imageData + ogray->widthStep*ppx))[ppy]; + uchar plum = ((uchar*)(ogray->imageData + ogray->widthStep*x_xmark[delaunay-1]))[x_ymark[delaunay-1]]; int diff = abs(plum-lum); @@ -753,7 +771,7 @@ void pix_opencv_lk :: processGrayImage(imageStruct &image) } } - cvCircle( grey, cvPointFrom32f(points[1][i]), 3, CV_RGB(0,255,0), -1, 8,0); + cvCircle( gray, cvPointFrom32f(points[1][i]), 3, CV_RGB(0,255,0), -1, 8,0); marked=0; for ( im=0; im<MAX_MARKERS; im++ ) @@ -765,7 +783,7 @@ void pix_opencv_lk :: processGrayImage(imageStruct &image) { char tindex[4]; sprintf( tindex, "%d", im+1 ); - cvPutText( grey, tindex, cvPointFrom32f(points[1][i]), &font, CV_RGB(255,255,255)); + cvPutText( gray, 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_found[im]=ftolerance; @@ -813,7 +831,7 @@ void pix_opencv_lk :: processGrayImage(imageStruct &image) if( add_remove_pt && count < MAX_COUNT ) { points[1][count++] = cvPointTo32f(pt); - cvFindCornerSubPix( grey, points[1] + count - 1, 1, + cvFindCornerSubPix( gray, points[1] + count - 1, 1, cvSize(win_size,win_size), cvSize(-1,-1), cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,20,0.03)); add_remove_pt = 0; @@ -854,7 +872,7 @@ void pix_opencv_lk :: processGrayImage(imageStruct &image) ( dst.x > 0 ) && ( dst.x < comp_xsize ) && ( org.y > 0 ) && ( org.y < comp_ysize ) && ( dst.y > 0 ) && ( dst.y < comp_ysize ) ) - cvLine( grey, iorg, idst, CV_RGB(255,0,0), 1, CV_AA, 0 ); + cvLine( gray, iorg, idst, CV_RGB(255,0,0), 1, CV_AA, 0 ); } } @@ -862,12 +880,12 @@ void pix_opencv_lk :: processGrayImage(imageStruct &image) } } - CV_SWAP( prev_grey, grey, swap_temp ); + CV_SWAP( prev_gray, gray, swap_temp ); CV_SWAP( prev_pyramid, pyramid, swap_temp ); CV_SWAP( points[0], points[1], swap_points ); need_to_init = 0; - memcpy( image.data, grey->imageData, image.xsize*image.ysize ); + memcpy( image.data, gray->imageData, image.xsize*image.ysize ); } ///////////////////////////////////////////////////////// @@ -960,22 +978,22 @@ void pix_opencv_lk :: delaunayMessCallback(void *data, t_symbol *s) void pix_opencv_lk :: pdelaunayMessCallback(void *data, t_floatarg fpoint, t_floatarg fthreshold) { - GetMyClass(data)->pdelaunayMess(fpoint, fthreshold); + GetMyClass(data)->pdelaunayMess((float)fpoint, (float)fthreshold); } -void pix_opencv_lk :: winSizeMess(float winsize) +void pix_opencv_lk :: winSizeMess(float fwinsize) { - if (winsize>1.0) win_size = (int)winsize; + if (fwinsize>1.0) win_size = (int)fwinsize; } -void pix_opencv_lk :: nightModeMess(float nightmode) +void pix_opencv_lk :: nightModeMess(float fnightmode) { - if ((nightmode==0.0)||(nightmode==1.0)) night_mode = (int)nightmode; + if ((fnightmode==0.0)||(fnightmode==1.0)) night_mode = (int)fnightmode; } -void pix_opencv_lk :: qualityMess(float quality) +void pix_opencv_lk :: qualityMess(float fquality) { - if (quality>0.0) quality = quality; + if (fquality>0.0) quality = fquality; } void pix_opencv_lk :: initMess(void) @@ -1074,15 +1092,15 @@ void pix_opencv_lk :: clearMess(void) } -void pix_opencv_lk :: minDistanceMess(float mindistance) +void pix_opencv_lk :: minDistanceMess(float fmindistance) { - if (mindistance>1.0) min_distance = (int)mindistance; + if (fmindistance>1.0) min_distance = (int)fmindistance; } -void pix_opencv_lk :: maxMoveMess(float maxmove) +void pix_opencv_lk :: maxMoveMess(float fmaxmove) { // has to be more than the size of a point - if (maxmove>=3.0) maxmove = (int)maxmove; + if (fmaxmove>=3.0) maxmove = (int)fmaxmove; } void pix_opencv_lk :: ftoleranceMess(float ftolerance) @@ -1098,12 +1116,13 @@ void pix_opencv_lk :: delaunayMess(t_symbol *s) delaunay = -1; } -void pix_opencv_lk :: pdelaunayMess(t_floatarg point, t_floatarg threshold) +void pix_opencv_lk :: pdelaunayMess(float fpoint, float fthreshold) { - if (((int)point>0) && ((int)point<MAX_MARKERS)) + if (((int)fpoint>0) && ((int)fpoint<MAX_MARKERS)) { - delaunay = (int)point; - threshold = (int)threshold; + delaunay = (int)fpoint; + threshold = (int)fthreshold; + // post( "pix_opencv_lk : setting threshold to : %d", threshold ); } } diff --git a/pix_opencv_lk.h b/pix_opencv_lk.h index 0a5c6e4..f60fa63 100755 --- a/pix_opencv_lk.h +++ b/pix_opencv_lk.h @@ -72,7 +72,7 @@ class GEM_EXTERN pix_opencv_lk : public GemPixObj void maxMoveMess(float maxmove); void ftoleranceMess(float ftolerance); void delaunayMess(t_symbol *s); - void pdelaunayMess(t_floatarg fpoint, t_floatarg fthreshold); + void pdelaunayMess(float fpoint, float fthreshold); int comp_xsize; int comp_ysize; @@ -107,7 +107,7 @@ class GEM_EXTERN pix_opencv_lk : public GemPixObj static void pdelaunayMessCallback(void *data, t_floatarg fpoint, t_floatarg fthreshold); // Internal Open CV data - IplImage *rgba, *rgb, *grey, *prev_grey, *pyramid, *prev_pyramid, *swap_temp; + IplImage *rgba, *rgb, *orgb, *gray, *ogray, *prev_gray, *pyramid, *prev_pyramid, *swap_temp; int x_xmark[MAX_MARKERS]; int x_ymark[MAX_MARKERS]; int x_found[MAX_MARKERS]; diff --git a/pix_opencv_surf-help.pd b/pix_opencv_surf-help.pd index 6b35907..5e5168d 100755 --- a/pix_opencv_surf-help.pd +++ b/pix_opencv_surf-help.pd @@ -1,6 +1,6 @@ #N canvas 117 89 1211 737 10; #X obj 218 -57 gemhead; -#X obj 218 457 pix_texture; +#X obj 212 459 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; @@ -17,19 +17,16 @@ #X msg 62 93 reset; #X obj 49 135 outlet; #X msg 107 89 dimen 320 240; -#X msg 202 89 frame 5; #X obj 107 51 t b b b; -#X connect 0 0 5 0; +#X connect 0 0 4 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 connect 4 0 3 0; +#X connect 4 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 msg 252 139 frame 5; #X connect 2 0 3 0; #X connect 3 0 4 0; #X connect 3 0 9 0; @@ -62,7 +59,7 @@ #X msg 333 -37 open \$1; #X obj 321 72 pix_film; #X msg 339 6 auto \$1; -#X obj 339 -12 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 1 +#X obj 339 -12 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1; #X obj 485 575 unpack f f; #X floatatom 486 600 5 0 0 0 - - -; @@ -79,7 +76,7 @@ #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 518 rectangle 4 3; #X obj 212 489 pix_resize 320 240; #X obj 410 -7 loadbang; #X msg 410 18 colorspace RGBA; diff --git a/pix_opencv_surf.cc b/pix_opencv_surf.cc index c1cfe9a..3ac75fa 100755 --- a/pix_opencv_surf.cc +++ b/pix_opencv_surf.cc @@ -871,7 +871,7 @@ void pix_opencv_surf :: delaunayMessCallback(void *data, t_symbol *s) void pix_opencv_surf :: pdelaunayMessCallback(void *data, t_floatarg fpoint, t_floatarg fthreshold) { - GetMyClass(data)->pdelaunayMess(fpoint, fthreshold); + GetMyClass(data)->pdelaunayMess((float)fpoint, (float)fthreshold); } void pix_opencv_surf :: nightModeMess(float nightmode) @@ -994,12 +994,13 @@ void pix_opencv_surf :: delaunayMess(t_symbol *s) x_delaunay = -1; } -void pix_opencv_surf :: pdelaunayMess(t_floatarg point, t_floatarg threshold) +void pix_opencv_surf :: pdelaunayMess(float point, float threshold) { if (((int)point>0) && ((int)point<MAX_MARKERS)) { x_delaunay = (int)point; x_threshold = (int)threshold; + // post( "pix_opencv_surf : setting threshold to : %d", x_threshold ); } } diff --git a/pix_opencv_surf.h b/pix_opencv_surf.h index bbc0277..e551d70 100755 --- a/pix_opencv_surf.h +++ b/pix_opencv_surf.h @@ -69,7 +69,7 @@ class GEM_EXTERN pix_opencv_surf : public GemPixObj void maxMoveMess(float maxmove); void ftoleranceMess(float ftolerance); void delaunayMess(t_symbol *s); - void pdelaunayMess(t_floatarg fpoint, t_floatarg fthreshold); + void pdelaunayMess(float fpoint, float fthreshold); int comp_xsize; int comp_ysize; |