Update curve_nodes.py

This commit is contained in:
kijai 2024-08-02 21:20:55 +03:00
parent 17f8d8db60
commit 4a2d499a5b

View File

@ -1256,6 +1256,12 @@ class PointsEditor:
"coordinates": ("STRING", {"multiline": False}), "coordinates": ("STRING", {"multiline": False}),
"bbox_store": ("STRING", {"multiline": False}), "bbox_store": ("STRING", {"multiline": False}),
"bboxes": ("STRING", {"multiline": False}), "bboxes": ("STRING", {"multiline": False}),
"bbox_format": (
[
'xyxy',
'xywh',
],
),
"width": ("INT", {"default": 512, "min": 8, "max": 4096, "step": 8}), "width": ("INT", {"default": 512, "min": 8, "max": 4096, "step": 8}),
"height": ("INT", {"default": 512, "min": 8, "max": 4096, "step": 8}), "height": ("INT", {"default": 512, "min": 8, "max": 4096, "step": 8}),
}, },
@ -1263,7 +1269,7 @@ class PointsEditor:
RETURN_TYPES = ("STRING", "STRING", "BBOX", "MASK") RETURN_TYPES = ("STRING", "STRING", "BBOX", "MASK")
RETURN_NAMES = ("coord_str", "normalized_str", "bbox", "bbox_mask") RETURN_NAMES = ("coord_str", "normalized_str", "bbox", "bbox_mask")
FUNCTION = "splinedata" FUNCTION = "pointdata"
CATEGORY = "KJNodes/weights" CATEGORY = "KJNodes/weights"
DESCRIPTION = """ DESCRIPTION = """
# WORK IN PROGRESS # WORK IN PROGRESS
@ -1274,28 +1280,16 @@ guaranteed!!
## Graphical editor to create coordinates ## Graphical editor to create coordinates
**Shift + click** to add control point at end. **Shift + click** to add control point at end.
**Ctrl + click** to add control point (subdivide) between two points. **Ctrl + click** to draw a box.
**Right click on a point** to delete it. **Right click on a point** to delete it.
Note that you can't delete from start/end. Note that you can't delete from start/end.
Right click on canvas for context menu: To add an image select the node and copy/paste or drag in the image.
These are purely visual options, doesn't affect the output: The image is saved to the node
- Toggle handles visibility
- Display sample points: display the points to be returned.
output types:
- mask batch
example compatible nodes: anything that takes masks
- list of floats
example compatible nodes: IPAdapter weights
- pandas series
example compatible nodes: anything that takes Fizz'
nodes Batch Value Schedule
- torch tensor
example compatible nodes: unknown
""" """
def splinedata(self, points_store, bbox_store, width, height, coordinates, bboxes): def pointdata(self, points_store, bbox_store, width, height, coordinates, bboxes, bbox_format="xyxy"):
coordinates = json.loads(coordinates) coordinates = json.loads(coordinates)
normalized = [] normalized = []
@ -1317,13 +1311,19 @@ output types:
else: else:
bboxes = [(int(bboxes["x"]), int(bboxes["y"]), int(bboxes["width"]), int(bboxes["height"]))] bboxes = [(int(bboxes["x"]), int(bboxes["y"]), int(bboxes["width"]), int(bboxes["height"]))]
bboxes_xyxy = []
# Draw the bounding box on the mask # Draw the bounding box on the mask
for bbox in bboxes: for bbox in bboxes:
x_min, y_min, w, h = bbox x_min, y_min, w, h = bbox
x_max = x_min + w x_max = x_min + w
y_max = y_min + h y_max = y_min + h
bboxes_xyxy.append((x_min, y_min, x_max, y_max))
mask[y_min:y_max, x_min:x_max] = 1 # Fill the bounding box area with 1s mask[y_min:y_max, x_min:x_max] = 1 # Fill the bounding box area with 1s
if bbox_format == "xyxy":
bboxes = bboxes_xyxy
mask_tensor = torch.from_numpy(mask) mask_tensor = torch.from_numpy(mask)
mask_tensor = mask_tensor.unsqueeze(0).float().cpu() mask_tensor = mask_tensor.unsqueeze(0).float().cpu()
#mask_tensor = mask_tensor[:,:,0] #mask_tensor = mask_tensor[:,:,0]