Docs CHOPs & sensing
MoveDetectDir
Reads which way things move in a camera or any image with optical flow and turns it into left/right and down/up channels, with thresholds, inversion and filtering, for swipe and gesture triggers.
∿ CHOPs & sensing ◆ Patreon · Base
Why use it
A swipe in front of a camera is an easy gesture for an audience to learn, and a fiddly one to read in TouchDesigner. A frame difference tells you that something moved, but not which way. For the direction you need optical flow, then a way to boil the flow field down to left, right, down and up, then thresholds and smoothing so that a twitch or camera noise does not count as a swipe.
MoveDetectDir is that chain in one node. It runs optical flow on the input, measures how much of the flow points left, right, down and up, and once the movement passes a threshold it comes out as two channels: one for left and right, one for down and up. Wave a hand across the camera and the channel swings to the side you swiped to.
Features
- Optical flow directionRuns optical flow on the input image and measures how much of the flow points left, right, down and up.
- Direction channelsOutputs LR and DU channels that swing toward the direction of movement once it passes a threshold, for swipe and gesture triggers.
- Filter out noise and small motionBlur on the input, a flow threshold and a movement threshold per axis keep camera noise and small motion from firing it.
- Invert a direction for mirrored camerasFlips either direction for a mirrored camera.
- Smooth the channelsSmooths the direction channels over a time you set.
How to use it
- Create it from the FNS tab of the OP Create dialog.
- Wire a camera into it, for example a Video Device In TOP for a webcam. Any image works.
- Swipe in front of the camera and watch LR and DU. If a swipe to the left reads as right, as it does with a mirrored camera, switch on Inverse X; Inverse Y does the same for down and up.
- Tune it to the room:
- If it fires on noise or on small movements in the background, raise Input Filter Size to blur away fine detail, or OptFlow Threshold to ignore weak flow.
- If a deliberate swipe does not register, lower Move Threshold X or Move Threshold Y.
- If the channels feel jumpy or slow, change Filter Width: a shorter time reacts faster, a longer one is steadier.
- Use the channels for anything that should react to the direction of motion as well as its amount: paging through a SlideShow with a gesture, or steering a scene from a crowd.
Inputs and output
- in1 (TOP): the image to watch, usually a camera.
- out1 (CHOP): two channels, LR for left and right movement and DU for down and up.
Get it
This tool unlocks with Patreon. It installs through the same picker as everything else and unlocks with the Patreon Base tier or higher, connected from inside TouchDesigner. Everything else in the toolkit stays free and MIT, and the membership is what keeps that work moving.
Parameters
Custom
| Control | Type / default | What it does |
|---|---|---|
Input Filter SizeSize |
number7 | Blur applied to the input before the optical flow, in pixels. More blur ignores small noise. |
Optflow LambdaLambda |
number0.1 | Smoothing of the optical flow: higher values give a steadier, less detailed flow. |
OptFlow ThresholdThreshold |
number0 | The smallest flow that counts as movement; weaker flow is ignored. |
Move Threshold XMovethresholdx |
number300 | How much horizontal movement it takes before LR swings left or right. |
Move Threshold YMovethresholdy |
number300 | How much vertical movement it takes before DU swings down or up. |
Inverse XInversex |
on / offoff | Flip the left/right direction, for a mirrored camera. |
Inverse YInversey |
on / offoff | Flip the down/up direction. |
Filter WidthWidth |
number0.2 | How long the output channels are smoothed over, in seconds. |