OpenCV goodFeaturesToTrack_0
The corner detector that's quietly one of the pack's best nodes
- image
- corners
- mask
- nparray
Most nodes in this pack are either plumbing or museum pieces. goodFeaturesToTrack_0 is the real thing: it finds corners - the strong, distinctive points in an image that are ideal for tracking, matching, and alignment. It wraps OpenCV's Shi-Tomasi corner detector, the algorithm that for twenty years has been the default way to say "give me the N most interesting points in this picture." In a ComfyUI workflow that's the seed of real computer vision: detect corners, then track them across frames with the pack's calcOpticalFlowPyrLK, or use them as reference points to align and crop a region.
How it works
Shi-Tomasi is a refinement of Harris corner detection. At every pixel it looks at the local gradient structure and computes a score based on the two eigenvalues of the covariance matrix. The key insight: a pixel is a good corner when both eigenvalues are large (strong edges in two directions). Shi-Tomasi uses min(λ1, λ2) as the score, which is more reliable than Harris's combined response and is why it became the go-to for tracking.
The inputs map straight onto that algorithm:
- image (
NPARRAY): your BGR image. Feed it fromImage2Nparray- remember this pack works in BGR uint8, not Comfy's RGB float tensors. - maxCorners (
INT): the cap on how many corners to return.0means "no limit," but setting a sane number like100is how you keep the output manageable. - qualityLevel (
FLOAT): the quality threshold as a fraction of the best corner's score -0.01is the classic value; raise it to get fewer, stronger corners. - minDistance (
FLOAT): minimum pixels between corners, in pixels.10–20stops corners from clustering on one texture. - blockSize (
INT): the window size for computing gradients -3or7are the usual picks. - useHarrisDetector (
BOOLEAN):Falsegives you Shi-Tomasi (what you want).Trueswitches to the older Harris scoring. - k (
FLOAT): Harris's free parameter (0.04), only meaningful if the flag above isTrue.
There are two optional inputs - corners and mask, both NPARRAY. mask is genuinely useful: a single-channel array where nonzero pixels mark where to look, so you can restrict detection to a region of interest. corners is an out-parameter (a leftover from how OpenCV passes buffers); leave it disconnected and it defaults to None, which is correct.
The output is not an image
Important: the nparray output is an N×1×2 float32 array of (x, y) coordinates - a list of points, not pixels. If you drop it straight into Nparrays2Image, you'll get the pack's signature 'NoneType' object has no attribute 'shape' error, because this is not an image. To visualize, draw the points with the pack's circle_0 node, or feed the array into the optical-flow node. That mismatch is the #1 beginner trip-up with this family.
Install
Standard pack install:
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
or ComfyUI Manager, search "opencv-comfyui", restart. Depends on opencv-contrib-python (numpy/torch already ship with ComfyUI). No models, no keys.
Troubleshooting
img.type() == CV_8UC1assertion failure means you fed it a grayscale-when-it-wants-color mismatch or vice versa - convert withcvtColor(code6for BGR2GRAY) as the function demands.- Corner outputs that look wrong? Lower
qualityLevelto0.005or raiseminDistance; the defaults skew toward very few, very confident corners. - Startup
Cannot import name 'guidedFilter'= duplicate OpenCV wheels; keep oneopencv-contrib-python.
Corner detection is niche in image-gen land, but if you're doing frame alignment, region matching, or motion tracking, this is the node to build on - the most genuinely useful CV in the pack.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| image | NPARRAY | — | |
| maxCorners | INT | — | |
| qualityLevel | FLOAT | — | |
| minDistance | FLOAT | — | |
| blockSize | INT | — | |
| useHarrisDetector | BOOLEAN | — | |
| k | FLOAT | — | |
| cornersopt | NPARRAY | — | |
| maskopt | NPARRAY | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |