Nodes/opencv-comfyui/OpenCV goodFeaturesToTrack_0
ComfyUI Node

OpenCV goodFeaturesToTrack_0

The corner detector that's quietly one of the pack's best nodes

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV goodFeaturesToTrack_0
  • image
  • corners
  • mask
  • nparray
maxCorners
qualityLevel
minDistance
blockSize
useHarrisDetector
k

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 from Image2Nparray - remember this pack works in BGR uint8, not Comfy's RGB float tensors.
  • maxCorners (INT): the cap on how many corners to return. 0 means "no limit," but setting a sane number like 100 is how you keep the output manageable.
  • qualityLevel (FLOAT): the quality threshold as a fraction of the best corner's score - 0.01 is the classic value; raise it to get fewer, stronger corners.
  • minDistance (FLOAT): minimum pixels between corners, in pixels. 1020 stops corners from clustering on one texture.
  • blockSize (INT): the window size for computing gradients - 3 or 7 are the usual picks.
  • useHarrisDetector (BOOLEAN): False gives you Shi-Tomasi (what you want). True switches to the older Harris scoring.
  • k (FLOAT): Harris's free parameter (0.04), only meaningful if the flag above is True.

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_8UC1 assertion failure means you fed it a grayscale-when-it-wants-color mismatch or vice versa - convert with cvtColor (code 6 for BGR2GRAY) as the function demands.
  • Corner outputs that look wrong? Lower qualityLevel to 0.005 or raise minDistance; the defaults skew toward very few, very confident corners.
  • Startup Cannot import name 'guidedFilter' = duplicate OpenCV wheels; keep one opencv-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.

Categoryimage/OpenCV

Inputs (9)

NameTypeDefaultDescription
imageNPARRAY
maxCornersINT
qualityLevelFLOAT
minDistanceFLOAT
blockSizeINT
useHarrisDetectorBOOLEAN
kFLOAT
cornersoptNPARRAY
maskoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY