Add bbox_format option for bbox visualize node

This commit is contained in:
kijai 2025-08-15 12:46:02 +03:00
parent 87d0cf42db
commit 2f7300dc54

View File

@ -694,6 +694,7 @@ class BboxVisualize:
"images": ("IMAGE",), "images": ("IMAGE",),
"bboxes": ("BBOX",), "bboxes": ("BBOX",),
"line_width": ("INT", {"default": 1,"min": 1, "max": 10, "step": 1}), "line_width": ("INT", {"default": 1,"min": 1, "max": 10, "step": 1}),
"bbox_format": (["xywh", "xyxy"], {"default": "xywh"}),
}, },
} }
@ -706,10 +707,17 @@ Visualizes the specified bbox on the image.
CATEGORY = "KJNodes/masking" CATEGORY = "KJNodes/masking"
def visualizebbox(self, bboxes, images, line_width): def visualizebbox(self, bboxes, images, line_width, bbox_format):
image_list = [] image_list = []
for image, bbox in zip(images, bboxes): for image, bbox in zip(images, bboxes):
if bbox_format == "xywh":
x_min, y_min, width, height = bbox x_min, y_min, width, height = bbox
elif bbox_format == "xyxy":
x_min, y_min, x_max, y_max = bbox
width = x_max - x_min
height = y_max - y_min
else:
raise ValueError(f"Unknown bbox_format: {bbox_format}")
# Ensure bbox coordinates are integers # Ensure bbox coordinates are integers
x_min = int(x_min) x_min = int(x_min)
@ -753,5 +761,3 @@ Visualizes the specified bbox on the image.
image_list.append(img_with_bbox) image_list.append(img_with_bbox)
return (torch.cat(image_list, dim=0),) return (torch.cat(image_list, dim=0),)
return (torch.cat(image_list, dim=0),)