OpenCV fitEllipseDirect_0
Fastest ellipse fit in the pack, and it talks in strings
- points
- literal
Fit an ellipse to a mess of 2D points and do it fast. That's fitEllipseDirect_0, the ComfyUI wrapper around OpenCV's fitEllipseDirect - the direct least-squares method from Fitzgibbon's classic paper, and the simplest of the three ellipse fits in this pack.
When do you actually need it? Anywhere a roughly-elliptical shape has been detected and you want its geometry - center, width and height, rotation angle. Feed it the points of a detected contour and it hands back a fitted ellipse. The "Direct" variant does one clean algebraic solve and stops; no iterative refinement, no robustness pass. That makes it the quickest of the three, and the one that can get twitchy if your points are noisy or one side of the ellipse is missing. For clean, dense point sets it's the one you want.
It sits in the same family as fitEllipseAMS and the default fitEllipse - the pack generated all three because OpenCV exposes all three. AMS handles outliers better; Direct is the fast, no-frills classic. Pick based on how dirty your points are.
Inputs and outputs
One input, one output, both simple:
-
points (
NPARRAY) - 2D points, typically N×2(x, y)coordinates from a contour or detection step. -
literal (
STRING) - the fitted ellipse as a Python literal string:((center_x, center_y), (width, height), angle), angle in degrees.
Notice the output type. Because this pack is auto-generated from OpenCV's type stubs, and a RotatedRect is a composite type the generator couldn't support, you get the result as a string rather than numbers. If you need that angle to drive a rotation node, you'll be parsing text. It's clunky, but it's the pack's design - the README calls these nodes "ugly and complex to use" and the author is upfront that convenience nodes are still on the todo list.
Installing
This ships in geroldmeisinger/opencv-comfyui, which wraps hundreds of standalone OpenCV functions in one install. Via ComfyUI Manager, search "opencv-comfyui". Or:
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
Restart ComfyUI after cloning. The pack's requirements.txt pulls in opencv-contrib-python, numpy, and torch, so the Python side is usually covered - but if you run a bare environment, pip install opencv-contrib-python won't hurt.
Common issues
Three pack-wide gotchas apply here. First, Comfy images are IMAGE tensors; this node wants NPARRAY, so route through Image2Nparray (in) and Nparrays2Image (out). Second, Image2Nparray refuses batches bigger than one - keep batch_size==1. Third, points must actually be a coordinate array, not an image; feeding it pixels produces shape errors.
And one fit-specific trap: because Direct does no robust refinement, a few bad points can pull the ellipse noticeably. If your fit keeps coming out lopsided, that's usually noisy points, not a broken node - switch to fitEllipseAMS and see if it settles down.
This is a niche node for geometry analysis inside ComfyUI, not a filter you'll use every day. But when you need a fast ellipse fit, it's exactly right.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| points | NPARRAY | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| literal | STRING | — |