@ignix-social/creator 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -2
- package/dist/box-kit/comfyui/locks/linux-x64.txt +2409 -0
- package/dist/box-kit/comfyui/locks/macos-arm64.txt +2243 -0
- package/dist/box-kit/comfyui/locks/windows-x64.txt +2322 -0
- package/dist/box-kit/comfyui/recast/LICENSE-WAN.txt +201 -0
- package/dist/box-kit/comfyui/recast/people.py +115 -0
- package/dist/box-kit/comfyui/recast/persons.py +90 -0
- package/dist/box-kit/comfyui/recast/prep.py +204 -0
- package/dist/box-kit/comfyui/recast/wan_pose_draw.py +1368 -0
- package/dist/box-kit/comfyui/recast/wan_pose_utils.py +1160 -0
- package/dist/box-kit/comfyui/recast/wan_utils.py +227 -0
- package/dist/box-kit/comfyui/workflows/infinitetalk.v1.json +94 -0
- package/dist/box-kit/comfyui/workflows/wan22-i2v-14b.v1.json +112 -0
- package/dist/box-kit/comfyui/workflows/wan22-i2v.v1.json +62 -0
- package/dist/cli.cjs +23811 -0
- package/dist/core.cjs +63459 -0
- package/dist/sfx-kit/achievement.wav +0 -0
- package/dist/sfx-kit/applause.wav +0 -0
- package/dist/sfx-kit/aww.wav +0 -0
- package/dist/sfx-kit/boing.wav +0 -0
- package/dist/sfx-kit/bonk.wav +0 -0
- package/dist/sfx-kit/boo.wav +0 -0
- package/dist/sfx-kit/boom.wav +0 -0
- package/dist/sfx-kit/camera-shutter.wav +0 -0
- package/dist/sfx-kit/cash-register.wav +0 -0
- package/dist/sfx-kit/cheer.wav +0 -0
- package/dist/sfx-kit/clap-hit.wav +0 -0
- package/dist/sfx-kit/click.wav +0 -0
- package/dist/sfx-kit/clock-tick.wav +0 -0
- package/dist/sfx-kit/coffee-pour.wav +0 -0
- package/dist/sfx-kit/coin.wav +0 -0
- package/dist/sfx-kit/coins.wav +0 -0
- package/dist/sfx-kit/correct.wav +0 -0
- package/dist/sfx-kit/countdown-beep.wav +0 -0
- package/dist/sfx-kit/crickets.wav +0 -0
- package/dist/sfx-kit/ding.wav +0 -0
- package/dist/sfx-kit/door-bell.wav +0 -0
- package/dist/sfx-kit/door-knock.wav +0 -0
- package/dist/sfx-kit/error.wav +0 -0
- package/dist/sfx-kit/flash.wav +0 -0
- package/dist/sfx-kit/gasp.wav +0 -0
- package/dist/sfx-kit/glitch.wav +0 -0
- package/dist/sfx-kit/heartbeat.wav +0 -0
- package/dist/sfx-kit/honk.wav +0 -0
- package/dist/sfx-kit/impact.wav +0 -0
- package/dist/sfx-kit/laugh.wav +0 -0
- package/dist/sfx-kit/level-up.wav +0 -0
- package/dist/sfx-kit/message-received.wav +0 -0
- package/dist/sfx-kit/message-sent.wav +0 -0
- package/dist/sfx-kit/notification.wav +0 -0
- package/dist/sfx-kit/ooh.wav +0 -0
- package/dist/sfx-kit/page-turn.wav +0 -0
- package/dist/sfx-kit/paper-crumple.wav +0 -0
- package/dist/sfx-kit/pen-write.wav +0 -0
- package/dist/sfx-kit/phone-vibrate.wav +0 -0
- package/dist/sfx-kit/pop-clean.wav +0 -0
- package/dist/sfx-kit/pop.wav +0 -0
- package/dist/sfx-kit/punch.wav +0 -0
- package/dist/sfx-kit/record-scratch.wav +0 -0
- package/dist/sfx-kit/reverse-cymbal.wav +0 -0
- package/dist/sfx-kit/rimshot.wav +0 -0
- package/dist/sfx-kit/riser-short.wav +0 -0
- package/dist/sfx-kit/sad-trombone.wav +0 -0
- package/dist/sfx-kit/scroll.wav +0 -0
- package/dist/sfx-kit/slide-whistle.wav +0 -0
- package/dist/sfx-kit/snap.wav +0 -0
- package/dist/sfx-kit/sparkle.wav +0 -0
- package/dist/sfx-kit/splat.wav +0 -0
- package/dist/sfx-kit/squeak.wav +0 -0
- package/dist/sfx-kit/stamp.wav +0 -0
- package/dist/sfx-kit/stomp.wav +0 -0
- package/dist/sfx-kit/sub-drop.wav +0 -0
- package/dist/sfx-kit/success.wav +0 -0
- package/dist/sfx-kit/swipe.wav +0 -0
- package/dist/sfx-kit/swoosh-down.wav +0 -0
- package/dist/sfx-kit/swoosh-up.wav +0 -0
- package/dist/sfx-kit/tap.wav +0 -0
- package/dist/sfx-kit/tape-stop.wav +0 -0
- package/dist/sfx-kit/thud.wav +0 -0
- package/dist/sfx-kit/timer-end.wav +0 -0
- package/dist/sfx-kit/toggle.wav +0 -0
- package/dist/sfx-kit/typing-mobile.wav +0 -0
- package/dist/sfx-kit/typing-slow.wav +0 -0
- package/dist/sfx-kit/typing.wav +0 -0
- package/dist/sfx-kit/whoosh-fast.wav +0 -0
- package/dist/sfx-kit/whoosh-heavy.wav +0 -0
- package/dist/sfx-kit/whoosh-soft.wav +0 -0
- package/dist/sfx-kit/wow.wav +0 -0
- package/dist/sfx-kit/wrong.wav +0 -0
- package/dist/sfx-kit/zipper.wav +0 -0
- package/dist/sfx-kit/zoom-in.wav +0 -0
- package/package.json +32 -4
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"""
|
|
2
|
+
WHO IS WHO in the video (ADR-0022 O6): every person, followed frame to frame,
|
|
3
|
+
so a request replaces the ONE person the customer chose — the official Wan
|
|
4
|
+
preprocessing takes the largest person of each frame and can jump between
|
|
5
|
+
two. Pure geometry (no GPU, no model): unit-tested in test_people.py.
|
|
6
|
+
|
|
7
|
+
A detection is (x1, y1, x2, y2, score) in pixels of the processed frames.
|
|
8
|
+
"""
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from dataclasses import dataclass, field
|
|
12
|
+
|
|
13
|
+
Box = tuple[float, float, float, float]
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def iou(a: Box, b: Box) -> float:
|
|
17
|
+
ix = max(0.0, min(a[2], b[2]) - max(a[0], b[0]))
|
|
18
|
+
iy = max(0.0, min(a[3], b[3]) - max(a[1], b[1]))
|
|
19
|
+
inter = ix * iy
|
|
20
|
+
union = (a[2] - a[0]) * (a[3] - a[1]) + (b[2] - b[0]) * (b[3] - b[1]) - inter
|
|
21
|
+
return inter / union if union > 0 else 0.0
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def area(b: Box) -> float:
|
|
25
|
+
return max(0.0, b[2] - b[0]) * max(0.0, b[3] - b[1])
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclass
|
|
29
|
+
class Track:
|
|
30
|
+
id: int
|
|
31
|
+
boxes: dict[int, Box] = field(default_factory=dict)
|
|
32
|
+
|
|
33
|
+
def last(self) -> tuple[int, Box]:
|
|
34
|
+
f = max(self.boxes)
|
|
35
|
+
return f, self.boxes[f]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def track(frames: list[list[Box]], min_iou: float = 0.3, max_gap: int = 8) -> list[Track]:
|
|
39
|
+
"""Greedy IoU linking: each detection joins the track it overlaps most
|
|
40
|
+
(seen within `max_gap` frames), else starts a new one."""
|
|
41
|
+
tracks: list[Track] = []
|
|
42
|
+
for f, dets in enumerate(frames):
|
|
43
|
+
taken: set[int] = set()
|
|
44
|
+
for d in sorted(dets, key=area, reverse=True):
|
|
45
|
+
best, best_iou = None, min_iou
|
|
46
|
+
for t in tracks:
|
|
47
|
+
lf, lb = t.last()
|
|
48
|
+
if t.id in taken or f - lf > max_gap or lf == f:
|
|
49
|
+
continue
|
|
50
|
+
o = iou(lb, d)
|
|
51
|
+
if o > best_iou:
|
|
52
|
+
best, best_iou = t, o
|
|
53
|
+
if best is None:
|
|
54
|
+
best = Track(id=len(tracks))
|
|
55
|
+
tracks.append(best)
|
|
56
|
+
best.boxes[f] = d
|
|
57
|
+
taken.add(best.id)
|
|
58
|
+
return tracks
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def people(tracks: list[Track], frames: int, min_share: float = 0.3, min_size: float = 0.1) -> list[Track]:
|
|
62
|
+
"""The tracks that are PEOPLE IN THE SHOT: present in at least `min_share`
|
|
63
|
+
of the frames and not tiny next to the biggest (a passer-by in the far
|
|
64
|
+
background is not someone to replace)."""
|
|
65
|
+
if not tracks:
|
|
66
|
+
return []
|
|
67
|
+
big = max(area(b) for t in tracks for b in t.boxes.values())
|
|
68
|
+
keep = []
|
|
69
|
+
for t in tracks:
|
|
70
|
+
typical = sorted(area(b) for b in t.boxes.values())[len(t.boxes) // 2]
|
|
71
|
+
if len(t.boxes) >= min_share * frames and typical >= min_size * big:
|
|
72
|
+
keep.append(t)
|
|
73
|
+
return sorted(keep, key=lambda t: -sum(area(b) for b in t.boxes.values()))
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class ManyPeople(Exception):
|
|
77
|
+
"""Several people and nobody chosen: the customer must pick one."""
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class PersonNotFound(Exception):
|
|
81
|
+
"""The chosen point is on nobody at that moment."""
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
class NoPerson(Exception):
|
|
85
|
+
"""Nobody to replace in the video."""
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def choose(
|
|
89
|
+
found: list[Track], frame: int | None, x: float | None, y: float | None, width: int, height: int
|
|
90
|
+
) -> Track:
|
|
91
|
+
"""The track the customer chose (a point in [0, 1] at a frame), or the
|
|
92
|
+
only person when there is one."""
|
|
93
|
+
if not found:
|
|
94
|
+
raise NoPerson()
|
|
95
|
+
if frame is None or x is None or y is None:
|
|
96
|
+
if len(found) > 1:
|
|
97
|
+
raise ManyPeople()
|
|
98
|
+
return found[0]
|
|
99
|
+
px, py = x * width, y * height
|
|
100
|
+
near = [t for t in found if frame in t.boxes]
|
|
101
|
+
inside = [t for t in near if t.boxes[frame][0] <= px <= t.boxes[frame][2] and t.boxes[frame][1] <= py <= t.boxes[frame][3]]
|
|
102
|
+
if inside:
|
|
103
|
+
# Overlapping boxes: the smallest one holding the point is the one touched.
|
|
104
|
+
return min(inside, key=lambda t: area(t.boxes[frame]))
|
|
105
|
+
raise PersonNotFound()
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def fill(t: Track, frames: int) -> list[Box]:
|
|
109
|
+
"""A box for every frame: missing ones from the nearest frame it was seen."""
|
|
110
|
+
seen = sorted(t.boxes)
|
|
111
|
+
out: list[Box] = []
|
|
112
|
+
for f in range(frames):
|
|
113
|
+
nearest = min(seen, key=lambda s: abs(s - f))
|
|
114
|
+
out.append(t.boxes[nearest])
|
|
115
|
+
return out
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"""
|
|
2
|
+
EVERY PERSON in a frame (ADR-0022 O6), by their body: YOLOX-S (Apache-2.0,
|
|
3
|
+
Megvii; the ONNX export from OpenCV Zoo), the same detector Creator runs on
|
|
4
|
+
the customer's computer to ask "which one?" (the box's `people` op), so both
|
|
5
|
+
sides count the same people. It replaces the detector bundled with Wan's
|
|
6
|
+
preprocessing (yolov10m, from an AGPL-3.0 project).
|
|
7
|
+
|
|
8
|
+
`decode` is pure numpy (unit-tested in test_persons.py); `Persons` runs the
|
|
9
|
+
model with onnxruntime, on the GPU when there is one.
|
|
10
|
+
"""
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import numpy as np
|
|
14
|
+
|
|
15
|
+
SIZE = 640
|
|
16
|
+
MIN_SCORE = 0.4
|
|
17
|
+
NMS_IOU = 0.5
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _anchors() -> tuple[np.ndarray, np.ndarray]:
|
|
21
|
+
grids, strides = [], []
|
|
22
|
+
for st in (8, 16, 32):
|
|
23
|
+
n = SIZE // st
|
|
24
|
+
xv, yv = np.meshgrid(np.arange(n), np.arange(n))
|
|
25
|
+
grids.append(np.stack((xv, yv), 2).reshape(-1, 2))
|
|
26
|
+
strides.append(np.full((n * n, 1), st))
|
|
27
|
+
return np.concatenate(grids), np.concatenate(strides)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
GRIDS, STRIDES = _anchors()
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def letterbox(rgb: np.ndarray) -> tuple[np.ndarray, float]:
|
|
34
|
+
"""The frame scaled into the model's square (top-left, grey padding)."""
|
|
35
|
+
import cv2
|
|
36
|
+
|
|
37
|
+
h, w = rgb.shape[:2]
|
|
38
|
+
r = min(SIZE / h, SIZE / w)
|
|
39
|
+
pad = np.full((SIZE, SIZE, 3), 114.0, np.float32)
|
|
40
|
+
small = cv2.resize(rgb, (int(w * r), int(h * r)))
|
|
41
|
+
pad[: small.shape[0], : small.shape[1]] = small
|
|
42
|
+
return pad.transpose(2, 0, 1)[None], r
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _nms(boxes: np.ndarray, scores: np.ndarray) -> list[int]:
|
|
46
|
+
order = list(np.argsort(-scores))
|
|
47
|
+
keep: list[int] = []
|
|
48
|
+
while order:
|
|
49
|
+
i = order.pop(0)
|
|
50
|
+
keep.append(i)
|
|
51
|
+
x1 = np.maximum(boxes[i, 0], boxes[order, 0])
|
|
52
|
+
y1 = np.maximum(boxes[i, 1], boxes[order, 1])
|
|
53
|
+
x2 = np.minimum(boxes[i, 2], boxes[order, 2])
|
|
54
|
+
y2 = np.minimum(boxes[i, 3], boxes[order, 3])
|
|
55
|
+
inter = np.clip(x2 - x1, 0, None) * np.clip(y2 - y1, 0, None)
|
|
56
|
+
area = lambda b: (b[..., 2] - b[..., 0]) * (b[..., 3] - b[..., 1]) # noqa: E731
|
|
57
|
+
iou = inter / (area(boxes[i]) + area(boxes[order]) - inter + 1e-9)
|
|
58
|
+
order = [o for o, v in zip(order, iou) if v <= NMS_IOU]
|
|
59
|
+
return keep
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def decode(out: np.ndarray, ratio: float, width: int, height: int) -> list[tuple[float, float, float, float]]:
|
|
63
|
+
"""The model's raw output (8400 x 85) -> person boxes (x1, y1, x2, y2) in
|
|
64
|
+
pixels of the frame, most confident first."""
|
|
65
|
+
xy = (out[:, :2] + GRIDS) * STRIDES
|
|
66
|
+
wh = np.exp(out[:, 2:4]) * STRIDES
|
|
67
|
+
score = out[:, 4] * out[:, 5] # an object, and that object is a person
|
|
68
|
+
sel = score >= MIN_SCORE
|
|
69
|
+
if not sel.any():
|
|
70
|
+
return []
|
|
71
|
+
boxes = np.concatenate([xy[sel] - wh[sel] / 2, xy[sel] + wh[sel] / 2], 1) / ratio
|
|
72
|
+
boxes[:, [0, 2]] = boxes[:, [0, 2]].clip(0, width)
|
|
73
|
+
boxes[:, [1, 3]] = boxes[:, [1, 3]].clip(0, height)
|
|
74
|
+
s = score[sel]
|
|
75
|
+
return [tuple(float(v) for v in boxes[i]) for i in _nms(boxes, s) if boxes[i, 2] > boxes[i, 0] and boxes[i, 3] > boxes[i, 1]]
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class Persons:
|
|
79
|
+
def __init__(self, checkpoint: str):
|
|
80
|
+
import onnxruntime
|
|
81
|
+
|
|
82
|
+
have = onnxruntime.get_available_providers()
|
|
83
|
+
providers = [p for p in ("CUDAExecutionProvider", "CPUExecutionProvider") if p in have]
|
|
84
|
+
self.session = onnxruntime.InferenceSession(checkpoint, providers=providers)
|
|
85
|
+
self.input = self.session.get_inputs()[0].name
|
|
86
|
+
|
|
87
|
+
def __call__(self, rgb: np.ndarray) -> list[tuple[float, float, float, float]]:
|
|
88
|
+
blob, ratio = letterbox(rgb)
|
|
89
|
+
out = self.session.run(None, {self.input: blob})[0][0]
|
|
90
|
+
return decode(out, ratio, rgb.shape[1], rgb.shape[0])
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
"""
|
|
2
|
+
"PUT ME IN THIS VIDEO" ON THIS COMPUTER (ADR-0022 O6): the recast's inputs for
|
|
3
|
+
ComfyUI's own WanAnimateToVideo node, made with the ComfyUI box's Python and
|
|
4
|
+
GPU. Creator talks to it over JSON lines on stdin/stdout (like OpenMontage's
|
|
5
|
+
creator_runner.py); ComfyUI itself still runs with no custom nodes.
|
|
6
|
+
|
|
7
|
+
The same steps as the Cloud Boost worker (engines/recast-worker/preprocess.py,
|
|
8
|
+
derived from Wan2.2's replacement preprocessing): the video at 30 fps and
|
|
9
|
+
720p area, every person found by their body (YOLOX-S, persons.py) and followed
|
|
10
|
+
(people.py), the chosen one's pose (ViTPose-H wholebody) drawn as Wan draws
|
|
11
|
+
it, their face crops, and the area to regenerate. That area is the person's
|
|
12
|
+
box: the worker's SAM2 mask ends as its bounding box too (get_aug_mask with a
|
|
13
|
+
1x1 grid), so no SAM2 here.
|
|
14
|
+
|
|
15
|
+
Request: {"id": 1, "op": "prep", "video": "/abs/in.mp4", "out": "/abs/dir",
|
|
16
|
+
"person": {"t": 2.0, "x": 0.4, "y": 0.5} | null}
|
|
17
|
+
Response: {"id": 1, "ok": true, "result": {"frames": 177, "width": 720, "height": 1280, "people": 1}}
|
|
18
|
+
{"id": 1, "ok": false, "error": "many_people" | "person_not_found" | "no_person" | ...}
|
|
19
|
+
Writes face.mp4 (512x512), pose.mp4, bg.mp4 and mask.mp4 into `out`.
|
|
20
|
+
Models: CREATOR_BOX_DATA/detect/yolox_s.onnx, CREATOR_BOX_DATA/pose/vitpose_h_wholebody_model.onnx.
|
|
21
|
+
"""
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
24
|
+
import json
|
|
25
|
+
import os
|
|
26
|
+
import sys
|
|
27
|
+
import traceback
|
|
28
|
+
from pathlib import Path
|
|
29
|
+
|
|
30
|
+
HERE = Path(__file__).resolve().parent
|
|
31
|
+
sys.path.insert(0, str(HERE))
|
|
32
|
+
|
|
33
|
+
FPS = 30
|
|
34
|
+
AREA = 1280 * 720
|
|
35
|
+
MAX_FRAMES = 15 * FPS
|
|
36
|
+
# The box grown like the worker's mask dilation (7 px kernel, 3 iterations).
|
|
37
|
+
GROW = 10
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _onnx():
|
|
41
|
+
# torch first: its CUDA libraries are the ones onnxruntime's CUDA provider loads.
|
|
42
|
+
try:
|
|
43
|
+
import torch # noqa: F401
|
|
44
|
+
except ImportError:
|
|
45
|
+
pass
|
|
46
|
+
import onnxruntime
|
|
47
|
+
|
|
48
|
+
try:
|
|
49
|
+
onnxruntime.preload_dlls()
|
|
50
|
+
except Exception: # noqa: BLE001 - older builds have no preload: torch's libraries are loaded
|
|
51
|
+
pass
|
|
52
|
+
return onnxruntime
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class ViTPose:
|
|
56
|
+
"""ViTPose-H wholebody (133 keypoints) through onnxruntime — Wan2.2's
|
|
57
|
+
pose2d.ViTPose without its torch dependency (Apache-2.0, Alibaba Wan Team)."""
|
|
58
|
+
|
|
59
|
+
def __init__(self, checkpoint: str):
|
|
60
|
+
ort = _onnx()
|
|
61
|
+
have = ort.get_available_providers()
|
|
62
|
+
providers = [p for p in ("CUDAExecutionProvider", "CPUExecutionProvider") if p in have]
|
|
63
|
+
self.session = ort.InferenceSession(checkpoint, providers=providers)
|
|
64
|
+
self.name = self.session.get_inputs()[0].name
|
|
65
|
+
|
|
66
|
+
def __call__(self, rgb, box):
|
|
67
|
+
import numpy as np
|
|
68
|
+
from wan_pose_utils import bbox_from_detector, crop, keypoints_from_heatmaps
|
|
69
|
+
|
|
70
|
+
bbox = np.array([*box, 1.0])
|
|
71
|
+
if (bbox[2] - bbox[0]) < 10 or (bbox[3] - bbox[1]) < 10:
|
|
72
|
+
bbox = np.array([0, 0, rgb.shape[1], rgb.shape[0], 1.0])
|
|
73
|
+
center, scale = bbox_from_detector(bbox, (256, 192), rescale=1.25)
|
|
74
|
+
img, _, _, _ = crop(rgb, center, scale, (256, 192))
|
|
75
|
+
mean, std = np.array([0.485, 0.456, 0.406]), np.array([0.229, 0.224, 0.225])
|
|
76
|
+
x = ((img / 255.0 - mean) / std).transpose(2, 0, 1).astype(np.float32)[None]
|
|
77
|
+
heat = self.session.run([], {self.name: x})[0]
|
|
78
|
+
points, prob = keypoints_from_heatmaps(
|
|
79
|
+
heatmaps=heat, center=np.array(center)[None], scale=np.array(scale)[None] * 200, unbiased=True, use_udp=False
|
|
80
|
+
)
|
|
81
|
+
return np.concatenate([points, prob], axis=2)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def read_frames(path: str):
|
|
85
|
+
"""The video at 30 fps (by time), each frame resized to a 720p area."""
|
|
86
|
+
import av
|
|
87
|
+
import numpy as np
|
|
88
|
+
from wan_utils import resize_by_area
|
|
89
|
+
|
|
90
|
+
out = []
|
|
91
|
+
with av.open(path) as c:
|
|
92
|
+
stream = c.streams.video[0]
|
|
93
|
+
next_t = 0.0
|
|
94
|
+
for frame in c.decode(stream):
|
|
95
|
+
t = float(frame.time or 0.0)
|
|
96
|
+
if t + 1e-6 < next_t:
|
|
97
|
+
continue
|
|
98
|
+
rgb = frame.to_ndarray(format="rgb24")
|
|
99
|
+
while next_t <= t + 1e-6 and len(out) < MAX_FRAMES:
|
|
100
|
+
out.append(resize_by_area(rgb, AREA, divisor=16))
|
|
101
|
+
next_t += 1.0 / FPS
|
|
102
|
+
if len(out) >= MAX_FRAMES:
|
|
103
|
+
break
|
|
104
|
+
return [np.ascontiguousarray(f) for f in out]
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def write_video(path: str, frames, gray: bool = False):
|
|
108
|
+
"""A near-lossless MPEG-4 file ComfyUI's LoadVideo reads (FFmpeg's own encoder)."""
|
|
109
|
+
import av
|
|
110
|
+
import numpy as np
|
|
111
|
+
|
|
112
|
+
h, w = frames[0].shape[:2]
|
|
113
|
+
with av.open(path, "w") as c:
|
|
114
|
+
s = c.add_stream("mpeg4", rate=FPS)
|
|
115
|
+
s.width, s.height, s.pix_fmt = w, h, "yuv420p"
|
|
116
|
+
s.bit_rate = 40_000_000
|
|
117
|
+
s.options = {"qscale": "1"}
|
|
118
|
+
for f in frames:
|
|
119
|
+
rgb = np.repeat(f[:, :, None], 3, axis=2) if gray else f
|
|
120
|
+
for p in s.encode(av.VideoFrame.from_ndarray(rgb, format="rgb24")):
|
|
121
|
+
c.mux(p)
|
|
122
|
+
for p in s.encode():
|
|
123
|
+
c.mux(p)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def prep(req: dict) -> dict:
|
|
127
|
+
import cv2
|
|
128
|
+
import numpy as np
|
|
129
|
+
|
|
130
|
+
import people
|
|
131
|
+
from persons import Persons
|
|
132
|
+
from wan_pose_draw import draw_aapose_by_meta_new
|
|
133
|
+
from wan_pose_utils import AAPoseMeta, load_pose_metas_from_kp2ds_seq
|
|
134
|
+
from wan_utils import get_face_bboxes
|
|
135
|
+
|
|
136
|
+
data = Path(os.environ.get("CREATOR_BOX_DATA", ""))
|
|
137
|
+
out = Path(req["out"])
|
|
138
|
+
out.mkdir(parents=True, exist_ok=True)
|
|
139
|
+
frames = read_frames(req["video"])
|
|
140
|
+
if not frames:
|
|
141
|
+
return {"ok": False, "error": "invalid_input"}
|
|
142
|
+
h, w = frames[0].shape[:2]
|
|
143
|
+
detector = Persons(str(data / "detect" / "yolox_s.onnx"))
|
|
144
|
+
found = people.people(people.track([detector(f) for f in frames]), len(frames))
|
|
145
|
+
at = req.get("person") or {}
|
|
146
|
+
frame_at = None if at.get("t") is None else min(len(frames) - 1, max(0, round(float(at["t"]) * FPS)))
|
|
147
|
+
try:
|
|
148
|
+
chosen = people.choose(found, frame_at, at.get("x"), at.get("y"), w, h)
|
|
149
|
+
except people.ManyPeople:
|
|
150
|
+
return {"ok": False, "error": "many_people"}
|
|
151
|
+
except people.PersonNotFound:
|
|
152
|
+
return {"ok": False, "error": "person_not_found"}
|
|
153
|
+
except people.NoPerson:
|
|
154
|
+
return {"ok": False, "error": "no_person"}
|
|
155
|
+
boxes = people.fill(chosen, len(frames))
|
|
156
|
+
|
|
157
|
+
pose = ViTPose(str(data / "pose" / "vitpose_h_wholebody_model.onnx"))
|
|
158
|
+
kp2ds = np.concatenate([pose(f, b) for f, b in zip(frames, boxes)], 0)
|
|
159
|
+
metas = load_pose_metas_from_kp2ds_seq(kp2ds, width=w, height=h)
|
|
160
|
+
|
|
161
|
+
faces, poses, bgs, masks = [], [], [], []
|
|
162
|
+
for frame, meta, box in zip(frames, metas, boxes):
|
|
163
|
+
x1, x2, y1, y2 = get_face_bboxes(meta["keypoints_face"][:, :2], scale=1.3, image_shape=(h, w))
|
|
164
|
+
crop = frame[y1:y2, x1:x2]
|
|
165
|
+
faces.append(cv2.resize(crop if crop.size else frame, (512, 512)))
|
|
166
|
+
poses.append(draw_aapose_by_meta_new(np.zeros_like(frame), AAPoseMeta.from_humanapi_meta(meta)))
|
|
167
|
+
bx1, by1 = max(0, int(box[0]) - GROW), max(0, int(box[1]) - GROW)
|
|
168
|
+
bx2, by2 = min(w, int(box[2]) + GROW), min(h, int(box[3]) + GROW)
|
|
169
|
+
mask = np.zeros((h, w), np.uint8)
|
|
170
|
+
mask[by1:by2, bx1:bx2] = 255
|
|
171
|
+
bg = frame.copy()
|
|
172
|
+
bg[by1:by2, bx1:bx2] = 0
|
|
173
|
+
bgs.append(bg)
|
|
174
|
+
masks.append(mask)
|
|
175
|
+
write_video(str(out / "face.mp4"), faces)
|
|
176
|
+
write_video(str(out / "pose.mp4"), poses)
|
|
177
|
+
write_video(str(out / "bg.mp4"), bgs)
|
|
178
|
+
write_video(str(out / "mask.mp4"), masks, gray=True)
|
|
179
|
+
return {"ok": True, "result": {"frames": len(frames), "width": w, "height": h, "people": len(found)}}
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
OPS = {"hello": lambda _req: {"ok": True, "result": {"prep": 1}}, "prep": prep}
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def main() -> None:
|
|
186
|
+
for line in sys.stdin:
|
|
187
|
+
line = line.strip()
|
|
188
|
+
if not line:
|
|
189
|
+
continue
|
|
190
|
+
msg_id = None
|
|
191
|
+
try:
|
|
192
|
+
msg = json.loads(line)
|
|
193
|
+
msg_id = msg.get("id")
|
|
194
|
+
op = OPS.get(msg.get("op"))
|
|
195
|
+
reply = op(msg) if op else {"ok": False, "error": "unsupported"}
|
|
196
|
+
except Exception: # noqa: BLE001 - one bad request must not end the process
|
|
197
|
+
traceback.print_exc(file=sys.stderr)
|
|
198
|
+
reply = {"ok": False, "error": "failed"}
|
|
199
|
+
sys.stdout.write(json.dumps({"id": msg_id, **reply}) + "\n")
|
|
200
|
+
sys.stdout.flush()
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
if __name__ == "__main__":
|
|
204
|
+
main()
|