Nodes/ComfyUI CV/cv2.integral3
ComfyUI Node

cv2.integral3

Two tables and a tilted one — the node for Haar-feature archaeology

By bmad4ever·Created 4 months ago·Updated 15 days ago· 1
cv2.integral3
  • src
  • sum
  • sqsum
  • tilted
◄sdepthsame as input►
◄sqdepthsame as input►

cv2.integral3 is cv2.integral2 plus one extra output: the tilted integral, a summed-area table built on 45°-rotated coordinates. It exists because Viola-Jones face detection used rotated rectangle features, and evaluating those in constant time needs a table accumulated along diagonals instead of rows and columns.

If that sentence doesn't describe your problem, you probably want cv2_integral or cv2_integral2 instead. This is the least-used of the three, and it's the one you reach for when you're reimplementing or debugging something that already speaks in tilted features.

It's a raw wrapper in bmad4ever/comfyui_cv, the pack that turns OpenCV functions into ComfyUI nodes.

Inputs and outputs

src takes an IMAGE, MASK or NPARRAY. Two optional depth widgets sit under it:

  • sdepth - depth of the straight sum table. same as input lets OpenCV choose; CV_32S / CV_32F / CV_64F are the explicit options.
  • sqdepth - depth of the squared table, CV_32F or CV_64F (same as input resolves to CV_64F).

Three NPARRAY outputs, in order: sum, sqsum, tilted. The first two are exactly what cv2_integral2 returns - (W+1)×(H+1) with a zero border, so any rectangle's sum is four lookups. The tilted table is the same idea accumulated along rotated axes, evaluated with a slightly different corner formula because the "rectangle" is a 45°-rotated one.

None of the three is an image. The pack types them as NPARRAY rather than IMAGE for a good reason: the image path min-max normalizes values outside 0..255, which would quietly destroy a table whose whole purpose is holding exact large integers. Consume them with Inspect CV Data (shape/statistics), Preview CV Array (normalized view or heatmap), CV Array Statistic, or arithmetic nodes, and cast heavily with CV Cast Array when you need to.

What you'd use it for

Honestly: reproducing or checking Haar-style feature math, where the tilted table lets you compute a rotated feature's response in O(1) instead of summing pixels. Also useful if you're building your own rotated-region statistics - a diagonal band of a texture, a slash-shaped defect region, anything where a 45° window is a better fit than an axis-aligned box.

For ordinary rectangle work, cv2_integral is cheaper and simpler; for mean-and-variance work, cv2_integral2 gives you the two tables without the third one's memory. The tilted table costs the same as the other two to build, so integral3 isn't free - it's three full (W+1)×(H+1) buffers per frame.

Installing the pack

Manager → search comfyui_cv, or:

cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_cv
pip install "opencv-contrib-python-headless~=5.0.0.93"

Python ≥ 3.12 and a ComfyUI recent enough for the V3 node API. The pack is curated against OpenCV 5.0.0.93. This is a core OpenCV function, so the contrib/non-contrib wheel question doesn't affect this node - though it decides whether a good chunk of the rest of the pack is present at all.

Where people get burned

Depth, again. Large frames and squared sums overflow CV_32S fast. If your variance numbers look unnervingly stable across wildly different regions, check the depth before you trust them.

Assuming tilted is "the same table, rotated". It's accumulated differently and indexed differently. Copying the axis-aligned corner formula onto it gives plausible-looking garbage.

Using it where integral2 would do. The third table is real memory and real time per frame, multiplied by your batch size.

Expecting the output in a viewer. Each output is data. Preview CV Array is how you look at one; CV Array → Image is how you make it a picture, and for an integral table that's almost never what you want.

The pack's README is candid that it's a personal, LLM-assisted project, not production software, and that a few registry entries can even exist without a working implementation in your OpenCV build. If this node errors out on a call, note the exact cv2 error before assuming your graph is wrong - the pack's own docs give exactly that example for a contrib function.

Categoryimage/CV/low-level/cv2 I

Inputs (3)

NameTypeDefaultDescription
srcNPARRAY,IMAGE,MASK - - - Accepts a ComfyUI IMAGE/MASK directly (frame 0 of a batch) or an NPARRAY. Arithmetic ops (add, multiply, etc.) process the full IMAGE batch when both inputs have the same batch size.
sdepthoptCOMBOsame as input - - -
sqdepthoptCOMBOsame as input - - -

Outputs (3)

NameTypeDescription
sumNPARRAY—
sqsumNPARRAY—
tiltedNPARRAY—