Nodes/ComfyUI CV/cv2.preCornerDetect
ComfyUI Node

cv2.preCornerDetect

A corner map, not corners — and the ksize that must not be 0

By bmad4ever·Created 4 months ago·Updated 15 days ago· 1
cv2.preCornerDetect
  • src
  • nparray
◄ksize0►
◄borderTypeBORDER_DEFAULT►

If you were hoping for a node that hands you a tidy list of corner coordinates, this isn't it - cv2.preCornerDetect produces a response map: a float image where corners are bright blobs and flat regions are dark. That's actually the more useful half for a lot of work, because a map you can threshold, blur and mask beats a list of points you can't.

What it is

A raw wrapper around OpenCV's corner-response function. It computes a corner-measure that is large where the local structure changes in two directions at once - the classic "corner-ness" definition - and returns it as an array rather than as detections. If you want the detections, you threshold this or feed the grayscale into goodFeaturesToTrack-style nodes, which is how the pack's feature pipeline works.

In practice that makes it a cheap saliency step: find the structural points of an image - a checkerboard, a printed page, a building façade, a texture - and use those as seeds for something else. In a generative pipeline that is usually a mask or a region-of-interest job, not a "find features to match" job.

How it works, and the two gotchas

The response comes back as a floating-point array, so it is data, not an image - the node's output socket is NPARRAY, and a preview node won't render it. To look at it, add CV Array → Image; to use it, threshold it (cv2.threshold, cv2.compare) or feed it into whatever downstream logic you have.

The two things that will bite you:

  1. ksize must be a positive size. This is the aperture of the Sobel derivative pair inside the corner measure. The widget starts at 0, and the OpenCV docs list no default for this parameter - the pack marks it as required for exactly that reason. 0 isn't "auto", it's invalid. 3 is the standard pick, 5 or 7 for a smoother/noisier response.
  2. It needs a single-channel image. The wrapper knows this and converts a colour IMAGE to grayscale for you automatically (preCornerDetect is in the pack's gray-required set), so a Load Image output just works. Hand it a mask and it goes straight through.

There's an optional borderType dropdown for the pixels at the frame edge. Leave it on BORDER_DEFAULT unless you have a reason; BORDER_WRAP is not supported and OpenCV will tell you so.

Inputs and outputs

src accepts a ComfyUI IMAGE or MASK directly - converted to uint8 gray, frame 0 of a batch, or all frames if you hand it a batch, since this function is in the pack's per-frame batch set. ksize as above, borderType optional. One output: nparray, the response map.

Wiring options: CV Array → Image to see it, then your usual grayscale display path with CV Color Map if you like your score maps in false colour. Downstream, any of the pack's point or contour machinery can consume the thresholded map.

Install

One node from ComfyUI CV - roughly 470 auto-generated cv2.* wrappers plus curated high-level nodes, by bmad4ever. Search comfyui_cv in ComfyUI Manager, or:

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

Restart ComfyUI after. Python ≥ 3.12 and a current V3-API ComfyUI are required; this node needs no models.

Common issues

"The output is black." You're looking at a preview of something that isn't an image, or you're thresholding a float map with a 0–255 mindset. Convert with CV Array → Image, and remember the raw response values are not normalised to 0–255 - normalise or threshold them with the right range in mind.

OpenCV error about ksize / assertion failure. You left ksize at 0.

Nothing but noise. Raise ksize, or blur the grayscale slightly first. The corner measure differentiates twice and it is honest about sensor noise - same reason post-processing.md says to blur before you differentiate rather than after.

Missing contrib nodes elsewhere. If other nodes from this pack are absent from the menu, you're probably on a non-contrib OpenCV wheel; tools/repair_opencv_contrib.py --check in the pack folder diagnoses it.

Categoryimage/CV/low-level/cv2 P

Inputs (3)

NameTypeDefaultDescription
srcNPARRAY,IMAGE,MASKSource single-channel 8-bit of floating-point image. 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.
ksizeINT0-2147483648–2147483647%Aperture size of the Sobel .
borderTypeoptCOMBOBORDER_DEFAULTPixel extrapolation method. See #BorderTypes. #BORDER_WRAP is not supported.

Outputs (1)

NameTypeDescription
nparrayNPARRAY—