diff options
author | Antoine Villeret <avilleret@users.sourceforge.net> | 2013-03-19 16:42:31 +0000 |
---|---|---|
committer | Antoine Villeret <avilleret@users.sourceforge.net> | 2013-03-19 16:42:31 +0000 |
commit | ecea3f1e323fd8004460fe11f4a99a99916a54f3 (patch) | |
tree | 2db806161281950aee71f89337ee958cee14d5a5 | |
parent | 98743470446a50a4351052fcd2d42dcc427d063e (diff) |
add a 08_GPU_morphology example
svn path=/trunk/externals/pix_opencv/; revision=17065
-rw-r--r-- | examples/08_GPU_morphology/08_GPU_morphology.pd | 129 | ||||
-rw-r--r-- | examples/08_GPU_morphology/dilate.frag | 121 | ||||
-rw-r--r-- | examples/08_GPU_morphology/dilate.vert | 8 | ||||
-rw-r--r-- | examples/08_GPU_morphology/erode.frag | 120 | ||||
-rw-r--r-- | examples/08_GPU_morphology/glsl_morph.pd | 59 |
5 files changed, 437 insertions, 0 deletions
diff --git a/examples/08_GPU_morphology/08_GPU_morphology.pd b/examples/08_GPU_morphology/08_GPU_morphology.pd new file mode 100644 index 0000000..4bf1188 --- /dev/null +++ b/examples/08_GPU_morphology/08_GPU_morphology.pd @@ -0,0 +1,129 @@ +#N canvas 448 234 1451 649 10; +#X declare -path ../..; +#X obj 109 243 cnv 15 600 180 empty empty empty 20 12 0 14 -4034 -66577 +0; +#X obj 233 340 cnv 15 200 240 empty empty empty 20 12 0 14 -261234 +-66577 0; +#X obj 758 319 loadbang; +#X obj 748 369 pix_texture; +#X obj 153 154 gemwin; +#X msg 136 115 create \, 1; +#X msg 209 115 0 \, destroy; +#X obj 529 46 pix_info _____________; +#X msg 639 116 \$1; +#X obj 529 25 pix_video; +#X obj 529 158 pix_texture; +#X text 238 365 shader inside -->; +#X obj 583 188 loadbang; +#X msg 583 211 1; +#X obj 975 335 loadbang; +#X msg 975 355 rectangle 1 \, quality 1; +#X obj 965 385 pix_texture; +#X obj 965 297 translateXYZ 0 4 -4; +#X obj 966 405 rectangle 4 3; +#X obj 748 389 rectangle 4 3; +#X msg 583 345 size \$1; +#X obj 529 68 pix_grey; +#X obj 529 90 pix_opencv_threshold; +#X obj 211 33 declare -path ../..; +#X obj 723 23 loadbang; +#X msg 723 45 255; +#X msg 754 45 130; +#X msg 758 338 rectangle 1 \, quality 1; +#X obj 547 118 loadbang; +#X msg 547 137 rectangle 1 \, quality 1; +#X floatatom 754 68 5 0 0 0 - - -; +#X msg 675 45 mode 1; +#X obj 317 279 vradio 15 1 0 2 empty empty mode 0 -8 0 10 -262144 -1 +-1 0; +#X text 332 277 dilate; +#X text 332 293 erode; +#X obj 537 257 r set_param; +#X obj 535 382 s shader_param; +#X obj 641 382 s pass; +#X obj 344 365 glsl_morph 1; +#X obj 117 285 s to_fb; +#X msg 117 265 rectangle 1 \, dimen 640 480; +#X obj 117 245 loadbang; +#X obj 589 5 loadbang; +#X msg 589 25 dimen 640 480; +#X obj 529 5 gemhead 0; +#X obj 965 263 gemhead 1; +#X obj 748 265 gemhead 50; +#X obj 173 244 r set_param; +#X obj 748 287 translateXYZ 0 -4 -4; +#X obj 344 385 glsl_morph 2; +#X obj 344 405 glsl_morph 3; +#X obj 344 425 glsl_morph 4; +#X obj 344 445 glsl_morph 5; +#X obj 344 465 glsl_morph 6; +#X obj 344 485 glsl_morph 7; +#X obj 344 505 glsl_morph 8; +#X obj 344 525 glsl_morph 9; +#X obj 344 545 glsl_morph 10; +#X floatatom 641 318 5 0 10 0 - - -; +#X obj 303 249 loadbang; +#X obj 317 314 s mode; +#X msg 451 322 pattern \$1; +#X text 241 451 10 pass morph; +#X obj 451 287 vradio 15 1 0 2 empty empty pattern 0 -8 0 10 -262144 +-1 -1 1; +#X text 466 285 cross; +#X text 466 301 square; +#X floatatom 583 319 5 1 3 0 - - -; +#X text 412 92 simple thresholding; +#X connect 2 0 27 0; +#X connect 3 0 19 0; +#X connect 5 0 4 0; +#X connect 6 0 4 0; +#X connect 7 0 21 0; +#X connect 7 6 8 0; +#X connect 9 0 7 0; +#X connect 10 1 16 1; +#X connect 10 1 38 0; +#X connect 12 0 13 0; +#X connect 13 0 58 0; +#X connect 14 0 15 0; +#X connect 15 0 16 0; +#X connect 16 0 18 0; +#X connect 17 0 16 0; +#X connect 20 0 36 0; +#X connect 21 0 22 0; +#X connect 22 0 10 0; +#X connect 24 0 25 0; +#X connect 24 0 26 0; +#X connect 24 0 31 0; +#X connect 25 0 22 1; +#X connect 26 0 30 0; +#X connect 27 0 3 0; +#X connect 28 0 29 0; +#X connect 29 0 10 0; +#X connect 30 0 22 2; +#X connect 31 0 22 0; +#X connect 32 0 60 0; +#X connect 35 0 63 0; +#X connect 35 0 66 0; +#X connect 38 0 49 0; +#X connect 40 0 39 0; +#X connect 41 0 40 0; +#X connect 42 0 43 0; +#X connect 43 0 9 0; +#X connect 44 0 9 0; +#X connect 45 0 17 0; +#X connect 46 0 48 0; +#X connect 47 0 40 0; +#X connect 48 0 3 0; +#X connect 49 0 50 0; +#X connect 50 0 51 0; +#X connect 51 0 52 0; +#X connect 52 0 53 0; +#X connect 53 0 54 0; +#X connect 54 0 55 0; +#X connect 55 0 56 0; +#X connect 56 0 57 0; +#X connect 57 0 3 1; +#X connect 58 0 37 0; +#X connect 59 0 32 0; +#X connect 61 0 36 0; +#X connect 63 0 61 0; +#X connect 66 0 20 0; diff --git a/examples/08_GPU_morphology/dilate.frag b/examples/08_GPU_morphology/dilate.frag new file mode 100644 index 0000000..8cbacdc --- /dev/null +++ b/examples/08_GPU_morphology/dilate.frag @@ -0,0 +1,121 @@ +// up to 7x7 dilate algorithm +// Antoine Villeret - 2012 + +#extension GL_ARB_texture_rectangle : enable + +uniform sampler2DRect frame; +uniform int size; +uniform int pattern; // 0 cross, 1 square + +vec2 texcoord0 = gl_TexCoord[0].st; + +vec2 texcoord00 = texcoord0 + vec2(-3, -3); +vec2 texcoord01 = texcoord0 + vec2(-2, -3); +vec2 texcoord02 = texcoord0 + vec2(-1, -3); +vec2 texcoord03 = texcoord0 + vec2(0, -3); +vec2 texcoord04 = texcoord0 + vec2(1, -3); +vec2 texcoord05 = texcoord0 + vec2(2, -3); +vec2 texcoord06 = texcoord0 + vec2(3, -3); + +vec2 texcoord10 = texcoord0 + vec2(-3, -2); +vec2 texcoord11 = texcoord0 + vec2(-2, -2); +vec2 texcoord12 = texcoord0 + vec2(-1, -2); +vec2 texcoord13 = texcoord0 + vec2(0, -2); +vec2 texcoord14 = texcoord0 + vec2(1, -2); +vec2 texcoord15 = texcoord0 + vec2(2, -2); +vec2 texcoord16 = texcoord0 + vec2(3, -2); + +vec2 texcoord20 = texcoord0 + vec2(-3, -1); +vec2 texcoord21 = texcoord0 + vec2(-2, -1); +vec2 texcoord22 = texcoord0 + vec2(-1, -1); +vec2 texcoord23 = texcoord0 + vec2(0, -1); +vec2 texcoord24 = texcoord0 + vec2(1, -1); +vec2 texcoord25 = texcoord0 + vec2(2, -1); +vec2 texcoord26 = texcoord0 + vec2(3, -1); + +vec2 texcoord30 = texcoord0 + vec2(-3, 0); +vec2 texcoord31 = texcoord0 + vec2(-2, 0); +vec2 texcoord32 = texcoord0 + vec2(-1, 0); +vec2 texcoord33 = texcoord0 + vec2(0, 0); // center pixel == texcoord0 +vec2 texcoord34 = texcoord0 + vec2(1, 0); +vec2 texcoord35 = texcoord0 + vec2(2, 0); +vec2 texcoord36 = texcoord0 + vec2(3, 0); + +vec2 texcoord40 = texcoord0 + vec2(-3, 1); +vec2 texcoord41 = texcoord0 + vec2(-2, 1); +vec2 texcoord42 = texcoord0 + vec2(-1, 1); +vec2 texcoord43 = texcoord0 + vec2(0, 1); +vec2 texcoord44 = texcoord0 + vec2(1, 1); +vec2 texcoord45 = texcoord0 + vec2(2, 1); +vec2 texcoord46 = texcoord0 + vec2(3, 1); + +vec2 texcoord50 = texcoord0 + vec2(-3, 2); +vec2 texcoord51 = texcoord0 + vec2(-2, 2); +vec2 texcoord52 = texcoord0 + vec2(-1, 2); +vec2 texcoord53 = texcoord0 + vec2(0, 2); +vec2 texcoord54 = texcoord0 + vec2(1, 2); +vec2 texcoord55 = texcoord0 + vec2(2, 2); +vec2 texcoord56 = texcoord0 + vec2(3, 2); + +vec2 texcoord60 = texcoord0 + vec2(-3, 3); +vec2 texcoord61 = texcoord0 + vec2(-2, 3); +vec2 texcoord62 = texcoord0 + vec2(-1, 3); +vec2 texcoord63 = texcoord0 + vec2(0, 3); +vec2 texcoord64 = texcoord0 + vec2(1, 3); +vec2 texcoord65 = texcoord0 + vec2(2, 3); +vec2 texcoord66 = texcoord0 + vec2(3, 3); + +void main (void) +{ + + float closed = texture2DRect(frame, texcoord33).r; // assume binary image + + // 1 pixel cross + closed = max(closed, texture2DRect(frame, texcoord34).r); + closed = max(closed, texture2DRect(frame, texcoord32).r); + closed = max(closed, texture2DRect(frame, texcoord23).r); + closed = max(closed, texture2DRect(frame, texcoord43).r); + + if ( pattern == 1 ) { + // 1 pixel square + closed = max(closed, texture2DRect(frame, texcoord22).r); + closed = max(closed, texture2DRect(frame, texcoord44).r); + closed = max(closed, texture2DRect(frame, texcoord24).r); + closed = max(closed, texture2DRect(frame, texcoord42).r); + } + + if ( size >= 2 ) { + // 2 pixels cross + closed = max(closed, texture2DRect(frame, texcoord35).r); + closed = max(closed, texture2DRect(frame, texcoord31).r); + closed = max(closed, texture2DRect(frame, texcoord13).r); + closed = max(closed, texture2DRect(frame, texcoord53).r); + + if ( pattern == 1 ) { + // 1 pixel square + closed = max(closed, texture2DRect(frame, texcoord11).r); + closed = max(closed, texture2DRect(frame, texcoord55).r); + closed = max(closed, texture2DRect(frame, texcoord15).r); + closed = max(closed, texture2DRect(frame, texcoord51).r); + } + } + + if ( size >= 3 ) { + // 3 pixels cross + closed = max(closed, texture2DRect(frame, texcoord36).r); + closed = max(closed, texture2DRect(frame, texcoord30).r); + closed = max(closed, texture2DRect(frame, texcoord03).r); + closed = max(closed, texture2DRect(frame, texcoord63).r); + + if ( pattern == 1 ) { + + // 3 pixel square + closed = max(closed, texture2DRect(frame, texcoord00).r); + closed = max(closed, texture2DRect(frame, texcoord66).r); + closed = max(closed, texture2DRect(frame, texcoord06).r); + closed = max(closed, texture2DRect(frame, texcoord60).r); + } + } + + gl_FragColor = vec4(vec3(closed),1); +} diff --git a/examples/08_GPU_morphology/dilate.vert b/examples/08_GPU_morphology/dilate.vert new file mode 100644 index 0000000..bda9f47 --- /dev/null +++ b/examples/08_GPU_morphology/dilate.vert @@ -0,0 +1,8 @@ +// Cyrille Henry 2007 + +void main() +{ + gl_TexCoord[0] = gl_MultiTexCoord0; + gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; + +} diff --git a/examples/08_GPU_morphology/erode.frag b/examples/08_GPU_morphology/erode.frag new file mode 100644 index 0000000..90ed15a --- /dev/null +++ b/examples/08_GPU_morphology/erode.frag @@ -0,0 +1,120 @@ +// up to 7x7 erode algorithm +// Antoine Villeret - 2012 + +#extension GL_ARB_texture_rectangle : enable + +uniform sampler2DRect frame; +uniform int size; +uniform int pattern; // 0 cross, 1 square + +vec2 texcoord0 = gl_TexCoord[0].st; + +vec2 texcoord00 = texcoord0 + vec2(-3, -3); +vec2 texcoord01 = texcoord0 + vec2(-2, -3); +vec2 texcoord02 = texcoord0 + vec2(-1, -3); +vec2 texcoord03 = texcoord0 + vec2(0, -3); +vec2 texcoord04 = texcoord0 + vec2(1, -3); +vec2 texcoord05 = texcoord0 + vec2(2, -3); +vec2 texcoord06 = texcoord0 + vec2(3, -3); + +vec2 texcoord10 = texcoord0 + vec2(-3, -2); +vec2 texcoord11 = texcoord0 + vec2(-2, -2); +vec2 texcoord12 = texcoord0 + vec2(-1, -2); +vec2 texcoord13 = texcoord0 + vec2(0, -2); +vec2 texcoord14 = texcoord0 + vec2(1, -2); +vec2 texcoord15 = texcoord0 + vec2(2, -2); +vec2 texcoord16 = texcoord0 + vec2(3, -2); + +vec2 texcoord20 = texcoord0 + vec2(-3, -1); +vec2 texcoord21 = texcoord0 + vec2(-2, -1); +vec2 texcoord22 = texcoord0 + vec2(-1, -1); +vec2 texcoord23 = texcoord0 + vec2(0, -1); +vec2 texcoord24 = texcoord0 + vec2(1, -1); +vec2 texcoord25 = texcoord0 + vec2(2, -1); +vec2 texcoord26 = texcoord0 + vec2(3, -1); + +vec2 texcoord30 = texcoord0 + vec2(-3, 0); +vec2 texcoord31 = texcoord0 + vec2(-2, 0); +vec2 texcoord32 = texcoord0 + vec2(-1, 0); +vec2 texcoord33 = texcoord0 + vec2(0, 0); // center pixel == texcoord0 +vec2 texcoord34 = texcoord0 + vec2(1, 0); +vec2 texcoord35 = texcoord0 + vec2(2, 0); +vec2 texcoord36 = texcoord0 + vec2(3, 0); + +vec2 texcoord40 = texcoord0 + vec2(-3, 1); +vec2 texcoord41 = texcoord0 + vec2(-2, 1); +vec2 texcoord42 = texcoord0 + vec2(-1, 1); +vec2 texcoord43 = texcoord0 + vec2(0, 1); +vec2 texcoord44 = texcoord0 + vec2(1, 1); +vec2 texcoord45 = texcoord0 + vec2(2, 1); +vec2 texcoord46 = texcoord0 + vec2(3, 1); + +vec2 texcoord50 = texcoord0 + vec2(-3, 2); +vec2 texcoord51 = texcoord0 + vec2(-2, 2); +vec2 texcoord52 = texcoord0 + vec2(-1, 2); +vec2 texcoord53 = texcoord0 + vec2(0, 2); +vec2 texcoord54 = texcoord0 + vec2(1, 2); +vec2 texcoord55 = texcoord0 + vec2(2, 2); +vec2 texcoord56 = texcoord0 + vec2(3, 2); + +vec2 texcoord60 = texcoord0 + vec2(-3, 3); +vec2 texcoord61 = texcoord0 + vec2(-2, 3); +vec2 texcoord62 = texcoord0 + vec2(-1, 3); +vec2 texcoord63 = texcoord0 + vec2(0, 3); +vec2 texcoord64 = texcoord0 + vec2(1, 3); +vec2 texcoord65 = texcoord0 + vec2(2, 3); +vec2 texcoord66 = texcoord0 + vec2(3, 3); + + +void main (void) +{ + float closed = texture2DRect(frame, texcoord33).r; // assume gray image + + // 1 pixel cross + closed = min(closed, texture2DRect(frame, texcoord34).r); + closed = min(closed, texture2DRect(frame, texcoord32).r); + closed = min(closed, texture2DRect(frame, texcoord23).r); + closed = min(closed, texture2DRect(frame, texcoord43).r); + + if ( pattern == 1 ) { + // 1 pixel diag + closed = min(closed, texture2DRect(frame, texcoord22).r); + closed = min(closed, texture2DRect(frame, texcoord44).r); + closed = min(closed, texture2DRect(frame, texcoord24).r); + closed = min(closed, texture2DRect(frame, texcoord42).r); + } + + if ( size >= 2 ) { + // 2 pixels cross + closed = min(closed, texture2DRect(frame, texcoord35).r); + closed = min(closed, texture2DRect(frame, texcoord31).r); + closed = min(closed, texture2DRect(frame, texcoord13).r); + closed = min(closed, texture2DRect(frame, texcoord53).r); + + if ( pattern == 1 ) { + // 2 pixel diag + closed = min(closed, texture2DRect(frame, texcoord11).r); + closed = min(closed, texture2DRect(frame, texcoord55).r); + closed = min(closed, texture2DRect(frame, texcoord15).r); + closed = min(closed, texture2DRect(frame, texcoord51).r); + } + } + + if ( size == 3 ) { + // 3 pixels cross + closed = min(closed, texture2DRect(frame, texcoord36).r); + closed = min(closed, texture2DRect(frame, texcoord30).r); + closed = min(closed, texture2DRect(frame, texcoord03).r); + closed = min(closed, texture2DRect(frame, texcoord63).r); + + if ( pattern == 1 ) { + // 3 pixel diag + closed = min(closed, texture2DRect(frame, texcoord00).r); + closed = min(closed, texture2DRect(frame, texcoord66).r); + closed = min(closed, texture2DRect(frame, texcoord06).r); + closed = min(closed, texture2DRect(frame, texcoord60).r); + } + } + + gl_FragColor = vec4(vec3(closed),1); +} diff --git a/examples/08_GPU_morphology/glsl_morph.pd b/examples/08_GPU_morphology/glsl_morph.pd new file mode 100644 index 0000000..bafa8bc --- /dev/null +++ b/examples/08_GPU_morphology/glsl_morph.pd @@ -0,0 +1,59 @@ +#N canvas 1 116 648 745 10; +#X obj 199 406 glsl_program; +#X obj 274 308 change; +#X obj 199 285 glsl_fragment; +#X obj 11 24 inlet; +#X obj 278 448 t b; +#X msg 274 329 link \$1; +#X msg 346 229 open dilate.frag; +#X obj 11 47 route float; +#X obj 346 176 sel 0 1; +#X msg 365 249 open erode.frag; +#X obj 74 97 spigot; +#X obj 118 97 spigot; +#X obj 107 40 == 0; +#X obj 254 374 r shader_param; +#X obj 107 -4 r pass; +#X obj 278 469 s set_param; +#X obj 382 583 outlet; +#X obj 199 237 gemframebuffer; +#X obj 145 468 translateXYZ 0 0 -4; +#X obj 145 538 pix_texture; +#X obj 145 558 square 4; +#X msg 162 517 quality 1 \, rectangle 0; +#X obj 162 496 loadbang; +#X obj 199 177 gemhead \$1; +#X obj 215 211 r to_fb; +#X obj 107 18 >= \$1; +#X obj 346 139 r mode; +#X connect 0 0 18 0; +#X connect 0 1 4 0; +#X connect 1 0 5 0; +#X connect 2 0 0 0; +#X connect 2 1 1 0; +#X connect 3 0 7 0; +#X connect 4 0 15 0; +#X connect 5 0 0 0; +#X connect 6 0 2 0; +#X connect 7 1 10 0; +#X connect 7 1 11 0; +#X connect 8 0 6 0; +#X connect 8 1 9 0; +#X connect 9 0 2 0; +#X connect 10 0 16 0; +#X connect 11 0 19 1; +#X connect 12 0 10 1; +#X connect 13 0 0 0; +#X connect 14 0 25 0; +#X connect 17 0 2 0; +#X connect 17 1 16 0; +#X connect 18 0 19 0; +#X connect 19 0 20 0; +#X connect 21 0 19 0; +#X connect 22 0 21 0; +#X connect 23 0 17 0; +#X connect 24 0 17 0; +#X connect 25 0 12 0; +#X connect 25 0 11 1; +#X connect 25 0 23 0; +#X connect 26 0 8 0; |