Navigation

Version

Examples

From the p5.videomotion documentation

These 15 sketches each show one part of p5.videomotion. Every page runs the sketch live and lists its full source. All of them use the webcam except Without a camera.

The examples load p5.js from a CDN, and browsers only give pages camera access over https:// or http://localhost. Serve this folder with a local web server (see Installation) rather than opening the files directly.

Basics

ExampleDescription
StarterThe smallest useful sketch: webcam, adaptive background, two zones and the debug overlay.
Without a cameraUses a p5.Graphics with moving shapes as the source. Useful for testing and for sketches where the input is generated or loaded rather than filmed.
Instance modeThe same starter written in p5 instance mode. createMotion is available on the instance as p.createMotion.
Camera in part of the canvasDraws the camera into a smaller frame and uses mapTo() so zones and blobs stay in canvas pixels that line up with it.

Zones

ExampleDescription
Zone padsFour zones along the top of the screen act like buttons. Each one flashes and counts when motion enters it.
Zone meter and thresholdShows a zone's amount as a live meter next to its threshold. Press UP and DOWN to change the threshold and see when the zone switches.
Direction inside zonesA grid of zones, each drawing an arrow for the average direction of movement inside it (zone.flow).

Blobs

ExampleDescription
Drawing blobsDraws each blob's convex hull, centre of mass, id and velocity yourself instead of using debug().
Blob trails and eventsKeeps a trail for each blob by its id, using onBlobEnter and onBlobExit to create and clean up the trails.

Optical flow

ExampleDescription
Flow fieldDraws every vector of the optical flow grid with forEachFlow(), coloured by direction.
Flow particles1,500 particles pushed around by motion.flowAt(). Wave your hands to sweep them.
Swipe gesturesDetects left, right, up and down swipes from averageFlow(), with a short cooldown so one gesture fires once.

Background and mask

ExampleDescription
Background modesCamera on the left, motion mask on the right. Switch modes with 1 (adaptive), 2 (static) and 3 (frame), relearn with SPACE, and change the threshold with + and -.
Mask ghostsUses motion.mask as an image: moving areas are added onto a slowly fading canvas, leaving ghost trails.

Performance

ExampleDescription
Resolution and manual updatesTurns off autoUpdate, times each motion.update() call and lets you change the processing resolution with a slider.