Roi Node ππ ‘π £π
Give Each Region Its Own Behavior
- mask
- next_roi
- ROI
Motion detection is only useful if it knows where to look - and what to do when it finds something. ROINode is the "where" and the "what": you feed it a mask that marks a region of your frame, pick an action, and it packages the whole thing into an ROI that this pack's Motion Controllers can act on. It's the difference between "motion happened somewhere" and "motion happened in the doorway, so toggle the light."
The mechanics are simple on the surface: it takes a MASK (draw it with Quick Shape Mask, or feed any segmentation mask), computes the bounding box of the non-zero pixels, and bundles the mask, bounds, action, and value into an ROI data blob. The next_roi input is where it gets interesting - ROIs chain together like a linked list, so you can define several regions and the motion controller walks them all in order on every frame. Different zones, different actions, one downstream controller.
The action enum is the part you'll actually think about, and it's worth mapping out because it's more than a toggle:
- toggle - flip between min and max each time motion is detected. On/off.
- momentary - max while motion is happening, min when it stops. A "hold" behavior.
- trigger - jump to max once per motion event, then fall back to min. A pulse.
- counter - count motion events; the output wraps within the minβmax range.
- add / subtract / multiply / divide - modify the current value by
valueon each motion event. - set - snap the output straight to
value.
So a door-region with toggle behaves differently from a hand-region with counter, and you feel that difference in how the effect responds.
The inputs that matter
- mask - defines the region. Only the non-zero area counts.
- action - the nine-choice enum above. The heart of the node.
- value - the operand for the math actions and the target for
set(default 0.1). - next_roi - chain another ROI; the controller processes them in order.
Output: one ROI, wired into Motion Controller or Integer Motion Controller's roi_chain.
Install & notes
Part of ryanontheinside/ComfyUI_RealtimeNodes - ComfyUI Manager (search "Control Nodes") or:
cd ComfyUI/custom_nodes
git clone https://github.com/ryanontheinside/ComfyUI_RealtimeNodes
cd ComfyUI_RealtimeNodes
pip install -r requirements.txt
An empty mask (all zeros) produces a zero-size ROI with no effect - harmless but useless, so make sure your mask actually has white pixels. The value steps by 0.01, so it's float-friendly even for the add/multiply actions. And one honest caveat: the ROI bounds come from the mask's bounding box, so a scattered mask with two separate blobs gets treated as one big region. For most setups that's fine, but if you need two independent regions, feed two ROINodes and chain them - don't try to fake it with one mask.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | β | |
| action | COMBO | 9 options: toggle, momentary, trigger, counter, add, subtract, +3 | |
| value | FLOAT | 0.10 | Value to use for mathematical operations |
| next_roiopt | ROI | β |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| ROI | ROI | β |