However in Sniff (on a Pi!) its really easy:
make display window device
make displayX number
make displayY number
when start
.forever
..tell display to "get event"
..wait 0.1 secs
make webcam device
when start
.forever
..tell webcam to "update"
..set displayX to 320
..set displayY to 240
..tell webcam to "draw"
In addition to just drawing the image, you can access the pixel values in it, so we could scale it down and copy it to a regular bitmap using:
make bitmap device
make scale number
when copyVidToBitmap
.make x number
.make y number
.set scale to 4
.set displayX to 640/scale
.set displayY to 480/scale
.tell bitmap to "new"
.repeat 640/scale using x
..repeat 480/scale using y
...set displayX to x*scale
...set displayY to y*scale
...tell webcam to "get pixel"
...set displayX to x
...set displayY to y
...tell bitmap to "set pixel"
We could save this out as a BMP, but in the demo we draw the smaller version over the larger one, and make it spin around!
..broadcast copyVidToBitmap and wait
..
..set bitmapValue to 10
..tell bitmap to "turn by"
..set displayX to 220
..set displayY to 140
There are probably a few wrinkles to work out (and it probably works best on a Pi2!), but at least for basic stuff, getting your live video feed into Sniff is really easy. How about writing the code to do your own green screen on the images, or edge detect the data to make a live line-drawing?
No comments:
Post a Comment