AI Vision with PictoBlox, lesson 3 of 15
Wave to pop the balloons: motion detection
Introduction
Can a computer tell when something moves? Yes, and it doesn't even need AI to do it. In this lesson you will build a game where balloons float up the screen, and you pop them by waving your hand over them in the air.
The computer compares this frame with the one before, like spot the difference. Pixels that changed show motion: 48% here. Past the limit, the balloon pops!
Working principle
- Video is a quick series of pictures called frames.
- Motion is how much the pixels changed between one frame and the next. PictoBlox gives it a number from 1 (hardly moving) to 100 (moving a lot).
- The block video (motion) on (sprite) tells you the motion just inside that sprite, so each balloon only feels movement on top of itself.
- The hat block when video motion > (10) starts a script when the motion goes over a number you choose. That number is called a threshold.
What you'll need
- PictoBlox with the Video Sensing extension added
- A webcam and a well-lit room
- Space to wave your arms
Working in real life
- Start a new project. Delete Tobi (or keep him as a mascot) and choose the Balloon1 sprite from the sprite library.
- Add the Video Sensing extension.
- Add a pop sound to the balloon: open the Sounds tab and pick Pop.
- Build the script below on the balloon sprite.
- Click the green flag, stand back from the webcam and wave at the balloon as it floats up.
Code
when green flag clicked
turn video [on]
set video transparency to (50)
set [score v] to (0)
forever
go to x: (pick random (-200) to (200)) y: (-170)
show
repeat until <(y position) > (170)>
change y by (3)
if <(video [motion] on [sprite]) > (30)> then
start sound [Pop]
change [score v] by (1)
hide
go to x: (0) y: (200)
end
end
endMake a variable called score first (Variables → Make a Variable). The balloon starts at a random place along the bottom, floats up, and if it feels enough motion it pops, adds a point and starts again.
Try it
- Change the threshold from 30 to 10, then to 60. What happens? A low threshold pops balloons too easily; a high one makes you wave like crazy.
- Make the balloon go faster each time you score. (Hint: use a variable instead of 3.)
- Duplicate the balloon so two balloons float up at once.
Check what you learnt
How does Video Sensing know something moved?
What is a threshold?
Why does each balloon use 'video motion on sprite' and not 'on stage'?
Conclusion
- Motion detection compares video frames to find what changed.
- Motion is a number from 1 to 100, and a threshold decides how much is enough.
- You can measure motion for the whole stage or just inside one sprite.
What next?
Motion only tells you that something moved. Next, use AI to find a face: Face detection: a crown that follows your face.

