Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions comfy_extras/nodes_sdpose.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import comfy.utils
import comfy.model_management
import numpy as np
import nodes
from tqdm import tqdm
from typing_extensions import override
from comfy_api.latest import ComfyExtension, io
Expand Down Expand Up @@ -384,6 +385,7 @@ def define_schema(cls):
category="image/transform",
search_aliases=["crop", "face crop", "bbox crop", "pose", "bounding box"],
description="Crop and resize regions from the input image batch based on provided bounding boxes.",
has_intermediate_output=True,
inputs=[
io.Image.Input("image"),
io.BoundingBox.Input("bboxes", force_input=True),
Expand All @@ -409,6 +411,14 @@ def execute(cls, image, bboxes, output_width, output_height, padding, keep_aspec
elif len(bboxes) == 0:
return io.NodeOutput(image)

ui = {
"source_images": nodes.PreviewImage().save_images(image[:1], "comfy.crop_bboxes.source")["ui"]["images"],
"input_bboxes": [
{k: int(b[k]) for k in ("x", "y", "width", "height")}
for b in bboxes[0]
],
}

crops = []

for frame_idx in range(total_frames):
Expand Down Expand Up @@ -462,10 +472,10 @@ def execute(cls, image, bboxes, output_width, output_height, padding, keep_aspec
crops.append(resized)

if not crops:
return io.NodeOutput(image)
return io.NodeOutput(image, ui=ui)

out_images = torch.cat(crops, dim=0).permute(0, 2, 3, 1) # (N, H, W, C)
return io.NodeOutput(out_images)
return io.NodeOutput(out_images, ui=ui)


class SDPoseExtension(ComfyExtension):
Expand Down
Loading