-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathCompositorTransformsOut3.py
65 lines (55 loc) · 2.13 KB
/
CompositorTransformsOut3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# import folder_paths
# from PIL import Image, ImageOps
# import numpy as np
# import torch
# from comfy_execution.graph import ExecutionBlocker
# import threading
# from server import PromptServer
# from aiohttp import web
import json
class CompositorTransformsOutV3:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"transforms": ("STRING", {"forceInput": True}),
"channel": ("INT", {"min": 1, "max": 8, "default": 1}),
"forceInt": ("BOOLEAN", {"default": True}),
},
"hidden": {
"extra_pnginfo": "EXTRA_PNGINFO",
"node_id": "UNIQUE_ID",
},
}
RETURN_TYPES = ("INT", "INT", "INT", "INT", "INT", "INT", "INT", "INT", "INT")
RETURN_NAMES = ("x", "y", "width", "height", "angle", "bbox x", "bbox y", "bbox width", "bbox height")
FUNCTION = "run"
CATEGORY = "image"
def run(self, **kwargs):
node_id = kwargs.pop('node_id', None)
channel = kwargs.pop('channel', 1)
transforms = kwargs.pop('transforms', {})
forceInt = kwargs.pop('forceInt', {})
# print(transforms)
data = json.loads(transforms)
padding = data["padding"]
# extract transforms
t = data["transforms"]
width = t[channel - 1]["xwidth"] * t[channel - 1]["scaleX"]
height = t[channel - 1]["xheight"] * t[channel - 1]["scaleY"]
# remove the padding as transforms are padding based
x = t[channel - 1]["left"] - padding
y = t[channel - 1]["top"] - padding
#angle
angle = t[channel - 1]["angle"]
# bounding box out
b = data["bboxes"]
bwidth = b[channel - 1]["xwidth"]
bheight = b[channel - 1]["xheight"]
# remove the padding as transforms are padding based
bx = b[channel - 1]["left"] - padding
by = b[channel - 1]["top"] - padding
if forceInt:
return (int(x), int(y), int(width), int(height), int(angle), int(bx), int(by), int(bwidth), int(bheight))
else:
return (x, y, width, height, angle, bx, by, bwidth, bheight)