Thanks a lot, very interesting!!
Just a quetion/problem. I'm trying your attached patch, and it works, but the Y position of the cursor seems to be systematically inverted!
I mean, if the actual blob (as I can see it in the preview "window") is on the top, the circle is drawn on the bottom of the screen!!
Is it an error in the patch, or is something working wrong in my case?
Aslo, the comments about "pix_blob" output say: "[upper left corner is 1, 1 down right corner is 0, 0]" According to what I can see by attaching number boxes to the 2nd and 3rd outlet, I would say "[upper left corner is 0, 0 down right corner is 1, 1]"
2008/1/21, Derek Holzer derek@umatic.nl:
See the attached patch, Sara Kolster and I use it in our workshops. Original by Ben Bogart, posted to the list when we had similar questions a few years ago.
best, d.
matteo sisti sette wrote:
I have to perform some very very simple computer-vision tasks (such as motion detection) on image data captured by a camera, and I was considering/evaluating the possibility of using GEM to do that.
-- derek holzer ::: http://www.umatic.nl ::: http://blog.myspace.com/macumbista ---Oblique Strategy # 58: "Do we need holes?"
#N canvas 574 31 1163 721 10; #X obj 277 131 pix_grey; #X msg 302 159 reset; #X obj 277 188 pix_background; #X msg 370 167 $1 $1 $1; #X msg 370 132 0.5; #X floatatom 370 151 5 0 0 0 - - -; #N canvas 486 104 585 607 cursor 0; #X obj 19 36 inlet; #X obj 231 32 inlet; #X obj 151 346 translateXYZ; #X text 62 150 0.64; #X text 34 151 1; #X obj 20 63 t f f; #X obj 34 176 -; #X text 59 177 X-Range; #X text 280 176 Y-Range; #X obj 53 215 expr (8/$f1); #X obj 20 215 -; #X obj 38 241 *; #X obj 26 95 max 0; #X obj 68 95 min 10; #X obj 58 131 f; #X obj 30 131 f; #X obj 39 267 - 4; #X text 278 148 0.64; #X text 250 147 1; #X obj 232 60 t f f; #X obj 250 172 -; #X obj 267 215 expr (8/$f1); #X obj 233 215 -; #X obj 251 241 *; #X obj 238 92 max 0; #X obj 280 92 min 10; #X obj 272 128 f; #X obj 246 127 f; #X obj 221 268 expr (-1*$f1)+4; #X obj 436 30 inlet; #X obj 437 61 * 10; #X obj 150 323 gemhead 15; #X obj 357 496 circle 0.1; #X obj 33 410 separator; #X obj 204 410 separator; #X obj 205 496 rectangle 0.2 0.01; #X obj 357 410 separator; #X msg 367 454 draw line; #X obj 367 433 loadbang; #X obj 152 371 colorRGB 1 0 0 1; #X obj 32 495 rectangle 0.01 0.2; #X msg 438 454 width $1; #X obj 437 398 int; #X obj 438 425 + 1; #X text 433 10 size; #X text 20 13 X-coordinate; #X text 221 11 Y-coordinate; #X text 278 370 color red; #X connect 0 0 5 0; #X connect 1 0 19 0; #X connect 2 0 39 0; #X connect 5 0 10 0; #X connect 5 0 12 0; #X connect 5 1 13 0; #X connect 6 0 9 0; #X connect 9 0 11 1; #X connect 10 0 11 0; #X connect 11 0 16 0; #X connect 12 0 15 0; #X connect 13 0 14 0; #X connect 14 0 6 1; #X connect 14 0 10 1; #X connect 14 0 13 1; #X connect 15 0 6 0; #X connect 15 0 12 1; #X connect 16 0 2 1; #X connect 19 0 22 0; #X connect 19 0 24 0; #X connect 19 1 25 0; #X connect 20 0 21 0; #X connect 21 0 23 1; #X connect 22 0 23 0; #X connect 23 0 28 0; #X connect 24 0 27 0; #X connect 25 0 26 0; #X connect 26 0 20 1; #X connect 26 0 22 1; #X connect 26 0 25 1; #X connect 27 0 20 0; #X connect 27 0 24 1; #X connect 28 0 2 2; #X connect 29 0 30 0; #X connect 30 0 32 1; #X connect 30 0 42 0; #X connect 31 0 2 0; #X connect 33 0 40 0; #X connect 34 0 35 0; #X connect 36 0 32 0; #X connect 37 0 32 0; #X connect 38 0 37 0; #X connect 39 0 33 0; #X connect 39 0 34 0; #X connect 39 0 36 0; #X connect 41 0 32 0; #X connect 42 0 43 0; #X connect 43 0 41 0; #X restore 282 510 pd cursor; #X obj 612 110 separator; #X obj 612 131 pix_texture; #X obj 612 152 square 4; #X obj 62 264 pix_texture; #X obj 62 244 alpha; #X obj 62 224 colourRGB 1 1 1 0.65; #X obj 62 284 translateXYZ -2.4 -2.4 0; #X obj 427 49 gemhead 10; #X obj 62 205 spigot; #X obj 99 160 tgl 20 0 empty empty empty 0 -6 0 8 -262144 -1 -1 1 1 ; #X obj 427 70 pix_video; #X obj 16 114 gemwin 30; #X msg 24 47 create; #X msg 25 71 destroy; #X obj 19 18 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 1 1 ; #X text 335 440 size; #X text 315 440 Y; #X text 289 439 X; #X text 859 10 by Ben Bogart (ben@ekran.org); #X obj 62 304 square 1.5; #X obj 277 106 separator; #X obj 278 423 pix_blob; #X obj 205 15 loadbang; #X msg 202 34 0; #X obj 426 15 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 1 1 ; #X msg 33 92 dimen 300 300; #X text 48 16 gem window; #X text 449 13 live input camera [firewire/usb]; #X text 610 224 [pix_background] 'removes' the background of an image by comparing a static image in memory to an incoming video stream. all values withing a given range are turned black. for best effect , place a camera on a static scene like a blank wall and hit 'reset'. then set the range control to cover any variance in the background. when a new object enters the scene it will be the only thing draw against a black background. use pix_chroma_key or pix_compare to add in images in place of the black.; #X text 611 199 --------------; #X text 607 85 image of the camera; #X text 608 93 --------------------; #X text 610 392 Inlet 2: float: range (<f> == <f> <f> <f>); #X text 609 341 Inlet 2: list: range ; in RGBA mode this is <+-red> <+-green> <+-blue> ; in YUV-mode this is <+-luma> <+-Cb> <+-Cr> ; in Gray-mode only the first value is important <+-gray>; #X text 612 211 Description: separate an object from background; #X text 215 80 motion tracking; #X text 216 88 ---------------; #X text 34 167 --------; #X text 440 171 threshold; #X text 605 446 [pix_blob] will calculate the "center-of-gravity" of a certain (combination of) channel(s).; #X text 604 434 --------------; #X text 607 476 You can choose the combination of channels used for the calculation by changing the <mode>. Valid modes are: 0(gray)(default) , 1(red) , 2(green) , 3(blue) , 4(alpha); #X text 608 520 pE: selecting "red" (1) will weight position of each pixel with its red-value. Pixels with "more" red will be weighted stronger , thus moving the "center of gravity" -- the blob position -- nearer to themself. The total amount of "red" in the image defines the size of the blob.; #X text 608 587 You can specify a custom combination of channels with <color-weights>. pE: "1 0 2" will give more weight to the blue-channel than to the red-channel , green- and alpha-values will be ignored. ; #X text 608 642 Specifing only one single color-weight <w> , is the same as "<w> <w> <w> 0"; #X text 387 190 ------------------------------- PIX_BACKGROUND; #X text 380 424 ------------------------------- PIX_BLOB; #X text 858 23 changed by Sara Kolster; #X text 857 36 [text from GEM help patches]; #X msg 304 373 <mode>; #X msg 329 395 <color-weights>; #X text 273 529 representation of the 'movement'; #X text 274 541 by a cursor. Click on pd cursor; #X text 273 553 to open the subpatch; #X text 37 441 outlet 1: gemlist; #X text 37 482 outlet 4: size; #X text 37 468 outlet 3: Y coordinate; #X text 37 454 outlet 2: X coordinate; #X text 35 496 [upper left corner is 1 , 1; #X text 36 509 down right corner is 0 , 0]; #X text 35 430 ----------------; #X text 37 421 OUTPUT PIX_BLOB ---------------; #X text 34 159 preview; #X obj 319 668 send tracking; #X obj 372 594 change; #X text 317 686 send coordinates to soundpatch; #X text 856 66 1] make gemwindow; #X text 856 79 2] turn on rendering; #X text 856 92 3] set the background; #X text 857 116 5] move object and receive information; #X text 856 104 4] turn on live input camera; #X msg 372 615 s $1; #X msg 331 615 y $1; #X msg 292 615 x $1; #X msg 110 571 send x $1; #X msg 153 595 send y $1; #X msg 178 618 send s $1; #X msg 51 685 connect localhost 3000; #X obj 124 643 netsend; #X connect 0 0 2 0; #X connect 1 0 2 0; #X connect 2 0 15 0; #X connect 2 0 28 0; #X connect 3 0 2 1; #X connect 4 0 5 0; #X connect 5 0 3 0; #X connect 7 0 8 0; #X connect 8 0 9 0; #X connect 10 0 13 0; #X connect 11 0 10 0; #X connect 12 0 11 0; #X connect 13 0 26 0; #X connect 14 0 17 0; #X connect 15 0 12 0; #X connect 16 0 15 1; #X connect 17 0 7 0; #X connect 17 0 27 0; #X connect 19 0 18 0; #X connect 20 0 18 0; #X connect 21 0 18 0; #X connect 27 0 0 0; #X connect 28 1 6 0; #X connect 28 1 80 0; #X connect 28 1 81 0; #X connect 28 2 6 1; #X connect 28 2 79 0; #X connect 28 2 82 0; #X connect 28 3 6 2; #X connect 28 3 71 0; #X connect 28 3 83 0; #X connect 29 0 30 0; #X connect 30 0 14 0; #X connect 31 0 14 0; #X connect 32 0 18 0; #X connect 56 0 28 1; #X connect 57 0 28 2; #X connect 71 0 78 0; #X connect 78 0 70 0; #X connect 79 0 70 0; #X connect 80 0 70 0; #X connect 81 0 85 0; #X connect 82 0 85 0; #X connect 83 0 85 0; #X connect 84 0 85 0;