OpenCV preCornerDetect_0
OpenCV preCornerDetect_0 and the corner-response map
- src
- dst
- nparray
preCornerDetect_0 is a corner-detection building block: it computes a corner response map - a per-pixel score saying "how corner-like is this spot?" - which is the first step in a classic OpenCV corner pipeline. It's cv2.preCornerDetect from the opencv-comfyui pack, which auto-generated ~635 nodes straight from OpenCV's Python type stubs.
The mechanism is elegant and worth understanding, because it's why this node exists at all. OpenCV computes the image's second-order derivatives (Dxx, Dyy, Dxy) and combines them into a harmonic-mean-style response: roughly (Dxx·Dyy − Dxy²) / (Dxx + Dyy). At a genuine corner, that response spikes; along a straight edge it doesn't. The result is a float image where high values mark potential corners. The "pre" in the name means it's the map you feed into further corner refinement - in classic OpenCV you'd threshold this map, do non-maximum suppression, and pass surviving points to cornerSubPix for sub-pixel precision.
The inputs that matter
src(NPARRAY) - must be a single-channel, floating-point image (CV_32ForCV_64F). The usual flow:Image2Nparray→cvtColorwith code6(BGR2GRAY) → convert to float. Feed it uint8 grayscale and the function rejects it.ksize(INT) - the aperture size of the Sobel derivative kernel: an odd number like3,5, or7. Bigger ksize = more blur = fewer, more robust corners. Start at3.borderType(INT) - an enum, not a friendly dropdown. The values you'll actually use:0= BORDER_CONSTANT,1= BORDER_REPLICATE,2= BORDER_REFLECT,4= BORDER_REFLECT_101 (the OpenCV default).1or4is a safe bet for real images.
The optional dst input is the OpenCV out-parameter; per the README, leave it unconnected. The output is a single nparray - a float response map, not a displayable image. Wire it into Nparrays2Image directly and you'll get a mostly-gray noise field; you're supposed to threshold it first.
What you'd use it for
The honest ComfyUI use case is thin but real: feature/corner detection for alignment and matching work - stabilizing two images, finding correspondences for warping, calibration-style tasks. There's also preCornerDetect_1 in this pack, its identical overload twin; pick whichever. If your workflow is pure text-to-image, you'll almost never need corners, and that's fine - this node is for the vision side of things.
Install and gotchas
Install via ComfyUI Manager (search "opencv-comfyui") or:
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
restart, then pip install opencv-contrib-python. Work in NPARRAY land (Image2Nparray in, batch size 1 only - ImageFromBatch length 1 if it complains), convert to grayscale and float before this node, and treat the output as a score map, not a picture.
A word of context from the author, Gerold Meisinger, who shipped the pack to r/comfyui in April 2025: these nodes are auto-generated, "ugly and complex to use. Expect dragons!" preCornerDetect_0 is a mid-tier dragon - the inputs are finicky (float, single-channel, integer enums), but the behavior is textbook OpenCV. If you know you need corner responses, it does the job exactly as documented.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| src | NPARRAY | — | |
| ksize | INT | — | |
| borderType | INT | — | |
| dstopt | NPARRAY | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |