Nodes/opencv-comfyui/OpenCV cornerHarris_0
ComfyUI Node

OpenCV cornerHarris_0

CornerHarris_0 — the classic corner detector, raw and honest

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV cornerHarris_0
  • src
  • dst
  • nparray
blockSize
ksize
k
borderType

The Harris corner detector is one of the oldest ideas in computer vision still running in production, and this node is its no-frills ComfyUI port: cv2.cornerHarris. Feed it a grayscale image and it returns a corner response map - one float per pixel saying "how much does this pixel look like a corner." It's the detector your mental model of "corner detection" was probably built from, and it's still the one to reach for when you need corners identified from local structure alone.

Let's be clear about where it fits in an AI workflow, because that's the honest part. This is not a LoRA, not a controlnet, not anything diffusion-shaped. It's the kind of deterministic primitive the KB's post-processing essay calls out: a millisecond, zero-inference operation that belongs in an alignment, stitching, or frame-registration stage. If you're aligning video frames before an img2img pass, finding calibration markers, or matching features between two renders of the same scene, this is your tool. If you just wanted to "make it look like a technical drawing," keep scrolling.

How it works

Harris looks at the gradient structure in a small neighborhood around each pixel - the same 2×2 structure tensor that cornerEigenValsAndVecs_0 exposes in full. Rather than giving you both eigenvalues, it collapses them into one score:

R = det(M) − k · trace(M)²

Where k is a free parameter (OpenCV's classic default is 0.04, and 0.04–0.06 is the usual range). The score is high at corners, negative along edges, near zero on flat areas. The output is a single-channel float32 map - and note, it's not scaled for viewing. You're expected to threshold it to get a binary corner mask, exactly like every OpenCV tutorial does with img[dst > 0.01 * dst.max()].

The inputs that matter

  • src - grayscale nparray. Color in → CV_8UC1 assertion error; convert with cvtColor code 6 first.
  • blockSize - neighborhood size for the structure tensor. Odd, usually 3–7. Larger = smoother, fewer candidates.
  • ksize - Sobel aperture for gradients, odd, 3 or 5.
  • k - the Harris free parameter. Default 0.04. Raise it toward 0.06 if you're getting spurious corner detections; lower it if you're missing real ones.
  • borderType - leave the default.
  • dst - the optional out-parameter the pack exposes; the README says to skip out-parameters, so skip it.

Install

This ships with opencv-comfyui (geroldmeisinger). Via ComfyUI Manager, search opencv-comfyui → install, or:

cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui

Then restart ComfyUI. Dependencies are opencv-contrib-python, numpy, torch - OpenCV is almost certainly already on your system from another pack; if not, pip install opencv-python-contrib. No model files, no downloads.

Common issues

  • CV_8UC1 assertion → grayscale it first. Non-negotiable.
  • Output looks black/white/broken → the response map isn't meant to be displayed raw. Threshold it, or pipe the map through Nparrays2Image after converting to a viewable range.
  • _0 vs _1 → identical overload twins from the auto-generator; pick either.
  • Batch size > 1Image2Nparray refuses it; use ImageFromBatch to pull a single frame.

The pack is auto-generated, so the node surface is blunt and the README's "expect dragons" warning applies. But Harris itself is rock-solid, 30-year-old math - get your image grayscale and thresholded, and it just works.

Categoryimage/OpenCV

Inputs (6)

NameTypeDefaultDescription
srcNPARRAY
blockSizeINT
ksizeINT
kFLOAT
borderTypeINT
dstoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY