Extensions/ComfyUI-Ultralytics-YOLO-BBOX-Coordinates
ComfyUI Extension

ComfyUI-Ultralytics-YOLO-BBOX-Coordinates

A minimal ComfyUI custom node for extracting pixel bounding-box coordinates from Ultralytics YOLO detections.

By kayselmecnun·Created 2 months ago·Updated 2 months ago· 0
kayselmecnun/ComfyUI-Ultralytics-YOLO-BBOX-Coordinates
Nodes
On cloudLocal install
Stars0
Updated2 months ago
Readme

YOLO BBox Coordinates for ComfyUI

A minimal ComfyUI custom node for extracting pixel bounding-box coordinates from Ultralytics YOLO detections.

This node is intended as a simple replacement for workflows that only use Impact Pack SEGS chains to get bounding-box coordinates. It does not depend on Impact Pack and does not output SEGS.

What It Does

The node accepts a ComfyUI IMAGE and a YOLO .pt model, runs object detection, draws red bounding boxes on the image, and returns directly usable pixel coordinates:

  • x1, y1, x2, y2
  • width, height
  • center_x, center_y
  • confidence
  • label
  • class_id
  • box_count
  • full detection JSON for all images in the batch

Node display name:

YOLO BBox Coordinates

Node category:

YOLO/coordinates

Why This Node Exists

Some ComfyUI YOLO nodes pass the raw ComfyUI tensor directly into Ultralytics. ComfyUI images are usually BHWC float tensors, while Ultralytics tensor inputs must be BCHW and stride-compatible. Image sizes such as 1200x672 can fail with errors like:

torch.Tensor inputs should be BCHW ... divisible by stride 32

This node avoids that issue by converting each ComfyUI image into a numpy uint8 HWC RGB image and passing that to:

model.predict(source=img_uint8, ...)

Ultralytics then handles resizing and padding internally.

Installation

Clone this repository into your ComfyUI custom nodes folder:

cd ComfyUI/custom_nodes
git clone https://github.com/kayselmecnun/ComfyUI-Ultralytics-YOLO-BBOX-Coordinates.git

Restart ComfyUI.

Dependencies

This node uses the installed ultralytics package.

If your ComfyUI environment does not already have it:

pip install ultralytics

No Impact Pack dependency is required.

Model Paths

The model_path input defaults to:

bbox/yolo11m.pt

The node checks model paths in this order:

  1. Absolute path, if model_path is absolute
  2. ComfyUI/models/ultralytics/<model_path>
  3. ComfyUI/models/<model_path>
  4. Current working directory relative path

Examples:

bbox/yolo11m.pt
ultralytics/bbox/yolo11m.pt
/absolute/path/to/yolo11m.pt

For the default path, place the model here:

ComfyUI/models/ultralytics/bbox/yolo11m.pt

Inputs

| Input | Type | Default | Notes | | --- | --- | --- | --- | | image | IMAGE | required | ComfyUI image tensor, BHWC, float 0..1 | | model_path | STRING | bbox/yolo11m.pt | YOLO .pt model path | | class_filter | STRING | person | Comma-separated class names or IDs. Empty means all classes | | conf | FLOAT | 0.25 | Detection confidence threshold | | iou | FLOAT | 0.70 | NMS IoU threshold | | imgsz | INT | 640 | Ultralytics inference image size | | device | STRING | cuda:0 | Use cpu, cuda:0, etc. | | half | BOOLEAN | false | Use half precision where supported | | sort_by | dropdown | x1 | Sort field | | sort_order | dropdown | ascending | Sort direction | | selected_index | INT | 0 | Selected detection after sorting | | max_boxes_json | INT | 50 | Max boxes per image in JSON. 0 includes all boxes |

Supported sort_by values:

x1
center_x
x2
y1
center_y
y2
area
confidence

Supported sort_order values:

ascending
descending

Class Filtering

class_filter accepts class names:

person
person,car

or numeric class IDs:

0
0,2

An empty string disables class filtering.

If a class name is not found in the model names, the node prints a warning in the ComfyUI console.

Outputs

| Output | Type | Description | | --- | --- | --- | | annotated_image | IMAGE | Input image with red boxes and index labels | | bbox_json | STRING | JSON containing detections for all batch images | | x1 | INT | Selected box left coordinate | | y1 | INT | Selected box top coordinate | | x2 | INT | Selected box right coordinate | | y2 | INT | Selected box bottom coordinate | | width | INT | x2 - x1 | | height | INT | y2 - y1 | | center_x | FLOAT | Selected box center X | | center_y | FLOAT | Selected box center Y | | confidence | FLOAT | Selected detection confidence | | label | STRING | Selected detection label | | class_id | INT | Selected detection class ID | | box_count | INT | Number of boxes found in the first image |

For image batches, bbox_json includes detections for every image. The scalar coordinate outputs refer to the selected detection from the first image in the batch.

JSON Format

The JSON output is stable and easy to parse:

{
  "images": [
    {
      "image_index": 0,
      "image_width": 1200,
      "image_height": 672,
      "box_count": 3,
      "boxes": [
        {
          "index": 0,
          "x1": 115,
          "y1": 184,
          "x2": 169,
          "y2": 548,
          "width": 54,
          "height": 364,
          "center_x": 142.0,
          "center_y": 366.0,
          "area": 19656,
          "confidence": 0.91,
          "class_id": 0,
          "label": "person"
        }
      ]
    }
  ],
  "selected": {
    "image_index": 0,
    "index": 0,
    "x1": 115,
    "y1": 184,
    "x2": 169,
    "y2": 548,
    "width": 54,
    "height": 364,
    "center_x": 142.0,
    "center_y": 366.0,
    "area": 19656,
    "confidence": 0.91,
    "class_id": 0,
    "label": "person"
  }
}

No Detection Behavior

If no boxes are found, the node returns:

  • the original image unchanged as annotated_image
  • valid empty JSON
  • coordinate outputs as 0
  • confidence as 0.0
  • label as an empty string
  • class_id as -1
  • box_count as 0

Common Usage

Leftmost person:

class_filter=person
sort_by=x1
sort_order=ascending
selected_index=0

Second person from left:

class_filter=person
sort_by=x1
sort_order=ascending
selected_index=1

Rightmost person:

class_filter=person
sort_by=x1
sort_order=descending
selected_index=0

Largest person:

class_filter=person
sort_by=area
sort_order=descending
selected_index=0

Notes

  • Coordinates are returned in the original image pixel coordinate space.
  • Boxes use xyxy format: x1, y1, x2, y2.
  • Loaded YOLO models are cached by resolved model path, so the model is not reloaded every run.
  • The input image tensor is not mutated.
  • The output image remains ComfyUI-compatible: BHWC, float32, range 0..1.