Nodes/ComfyUI-Teeth/Teeth Get First Seg
ComfyUI Node

Teeth Get First Seg

Grab the First Detected Region's Bounding Box (Without Fumbling With SEGS)

By steelan9199·Created 2 years ago·Updated about a year ago· 10
Teeth Get First Seg
  • segs
  • CenterX
  • CenterY
  • Left
  • Top
  • Right
  • Bottom
  • Width
  • Height

Impact Pack's SEGS format is powerful and annoying in equal measure. It's a (batch_info, [SEG, SEG, ...]) structure where each SEG carries a cropped image, a mask, a confidence, a label, and a bounding box - but pulling just the box out of one of them in the vanilla graph means routing SEGS through a detailer or writing something custom. Teeth Get First Seg is the shortcut: it takes a SEGS input, looks at the first segment, and hands you its bounding box as eight plain integers.

It comes from ComfyUI-Teeth, a small single-author utility pack. This node is barely more than a namedtuple unpacker - but a genuinely handy one, because the SEGS internals it reads (cropped_image, cropped_mask, confidence, crop_region, bbox, label, control_net_wrapper) are exactly Impact Pack's own structure, so it works with any node that emits SEGS - detectors, SAM providers, FaceDetailer's output.

How it works

The node does one job. It validates the SEGS structure, takes the first entry (segs[1][0]), reads its bbox as (x1, y1, x2, y2), and does a little arithmetic:

  • Left / Top / Right / Bottom - the raw box coordinates.
  • Width / Height - x2 - x1, y2 - y1.
  • CenterX / CenterY - the box midpoint.

Eight INT outputs, one for each. Nothing else, no filters, no options. It's the "give me the box of whatever was detected first" node.

Inputs and outputs that matter

There's exactly one input - segs (SEGS) - and the eight integer outputs above. Wire a SEGS source into it, and you can feed the resulting box straight into a crop node, a mask, a bounding-box-aware sampler, or a math node that decides what to do with the result.

Where it trips people up

Empty SEGS throws, it doesn't return zeros. The code raises a ValueError if there's no SEG object - so if your detector found nothing (no face, no region), this node hard-fails the run. In a batch job where some frames legitimately have no detections, that's a workflow-killer unless you gate it upstream.

It's the first SEG, period. No sorting, no "largest," no "closest to center." If your detector outputs segments in an order you don't control, "first" might not be the one you want. The node is honest about its name - you get the first box, and the rest of the list is ignored.

Coordinates are what Impact Pack gave you. The box comes straight from the detector's coordinate system, which can be relative to the original image or to a resized version depending on your detector provider. If crops look offset, that's the detector, not this node.

Install

ComfyUI Manager: search ComfyUI-Teeth. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/steelan9199/ComfyUI-Teeth

Restart ComfyUI. It has no dependencies beyond ComfyUI itself, and no model files. One thing to note: you'll also want Impact Pack installed if you're actually producing SEGS - this node only consumes them.

CategoryTeeth

Inputs (1)

NameTypeDefaultDescription
segsSEGS

Outputs (8)

NameTypeDescription
CenterXINT
CenterYINT
LeftINT
TopINT
RightINT
BottomINT
WidthINT
HeightINT