cv2.boxPoints
Unwrap a rotated rectangle into its four corners
- box
- corners
A rotated rectangle is stored compactly - a centre, a width and height, and an angle - because that's all cv2.minAreaRect needs to hand you, and it's the right form for drawing a tilted box. The moment you want the actual polygon, you need the corners, and that's the whole of cv2.boxPoints. One rotated rect in, a 4×2 float32 array out.
It's a raw wrapper in comfyui_cv, the pack of ~470 cv2.* nodes for ComfyUI. It's a tiny node, but it's the hinge between the "compact geometry" side of OpenCV - minAreaRect, fitEllipse, CamShift - and the "give me points" side, where perspective warps and polygon fills live.
When you'd use it
Three real cases, all variations on "I have a tilted region and I need its outline":
A perspective crop. cv2.getPerspectiveTransform needs four source points. Corners of a rotated rect is exactly four points, so minAreaRect → boxPoints → getPerspectiveTransform is the standard straighten-this-region chain - the thing you'd build to fix a skewed photo, a road sign, a document.
Drawing or masking the region. The pack's drawing primitives take point arrays: feed corners into fillConvexPoly to paint the region, or into the point-drawing helpers to mark each corner. That's how you visualize what a detector actually found without needing a bounding-box-specific overlay node.
Feeding geometry you computed yourself. Once you have the corners as numbers, everything downstream is just four points - computing a mean, checking an overlap, building a mask by hand, projecting into a 3D scene.
Inputs and output
box(required, default"") - the rotated rectangle. It's aCV_ROTATED_RECT,STRINGsocket, which means it behaves two ways: wire it from a producer (cv2.minAreaRect,cv2.fitEllipse,cv2.CamShiftall emit this type), or type the literal in the widget. The canonical literal is((cx, cy), (width, height), angle)with the angle in degrees; the author's tooltip notes the flat(cx, cy, w, h, angle)spelling is accepted too. Left empty, the node has nothing to expand.
Output is one socket:
corners- an NPARRAY of four points, float32, in cv2's fixed order: it starts at the corner with the greatest y (bottom-left in image coordinates, where y grows downward) and walks clockwise. Same order every time, so if you're indexing into it for a warp, you can rely on it.
Worth knowing about that compact form: size in a rotated rect isn't always the extent you'd measure with a ruler - OpenCV picks a representation, and the width/height can be swapped relative to what looks natural. That's precisely why boxPoints exists. The corners are the truth; the (w, h, angle) triple is one of several ways to describe them.
Install
cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_cv
Restart, or install through ComfyUI Manager (search "comfyui_cv"). Python ≥ 3.12, a recent ComfyUI on the V3 node API, and:
pip install "opencv-contrib-python-headless~=5.0.0.93"
That's the version the pack's behaviour is curated against. Nothing to download in terms of models - this node is pure geometry.
Common issues
Validation error before anything runs. The box widget is empty or malformed. It needs either a linked producer or a literal like ((100, 100), (60, 40), 30).
The corners look rotated by 90° from what you expected. That's the size/angle representation again, not a bug. If you're feeding a perspective transform and getting a sideways result, reorder the points (or sort them by your own rule) rather than fighting the origin.
The socket won't accept your array of points. It won't - corners is an output, and the input wants a rotated rect, not arbitrary points. If you have points and want a rect, that's cv2.minAreaRect, going the other direction.
The rect-driven nodes come out empty. Check whether the producer actually found anything. minAreaRect on an empty point set, or a tracking step that didn't converge, can hand you a degenerate box with zero size, and four corners that coincide look like nothing at all.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| box | CV_ROTATED_RECT,STRING | - - - A rotated rectangle: ((center_x, center_y), (width, height), angle in degrees). Wire it from cv2.fitEllipse / cv2.minAreaRect / cv2.CamShift, or type the literal (the flat (cx, cy, w, h, angle) spelling is accepted too). |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| corners | NPARRAY | — |