Repository navigation
Expand file tree
/
Copy pathShadowclone.py
More file actions
133 lines (109 loc) · 4.38 KB
/
Copy pathShadowclone.py
File metadata and controls
133 lines (109 loc) · 4.38 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import cv2
import numpy as np
import mediapipe as mp
import random
import pygame
# Initialize MediaPipe
mp_hands = mp.solutions.hands
mp_selfie = mp.solutions.selfie_segmentation
class UltimateKageBunshin:
def __init__(self):
self.hands = mp_hands.Hands(max_num_hands=2, min_detection_confidence=0.6)
self.segmentation = mp_selfie.SelfieSegmentation(model_selection=1)
# 🔊 Initialize Sound System
pygame.mixer.init()
self.clone_sound = pygame.mixer.Sound(
r"D:\python\python\shadow-clone-jutsu.mp3"
)
self.clone_sound.set_volume(1.0)
self.clones_active = False
self.cooldown = 0
self.smoke_timer = 0
self.particles = []
self.layout = [
(-350, -200, 0.45), (-150, -220, 0.4), (150, -220, 0.4), (350, -200, 0.45),
(-400, -100, 0.55), (-200, -120, 0.5), (200, -120, 0.5), (400, -100, 0.55),
(-450, 50, 0.7), (-250, 30, 0.65), (250, 30, 0.65), (450, 50, 0.7),
(-500, 200, 0.85), (-300, 180, 0.8), (300, 180, 0.8), (500, 200, 0.85),
(-550, -50, 0.6), (550, -50, 0.6)
]
def create_smoke_particles(self, h, w):
self.particles = []
for _ in range(120):
self.particles.append({
'pos': [random.randint(0, w), random.randint(0, h)],
'v': [random.uniform(-5, 5), random.uniform(-5, 5)],
'size': random.randint(10, 40),
'color': random.randint(200, 240)
})
self.smoke_timer = 20
def is_cross_seal(self, hand_res):
if not hand_res.multi_hand_landmarks or len(hand_res.multi_hand_landmarks) < 2:
return False
v_found, h_found = False, False
for hand_lms in hand_res.multi_hand_landmarks:
tip, mcp = hand_lms.landmark[8], hand_lms.landmark[5]
dx, dy = abs(tip.x - mcp.x), abs(tip.y - mcp.y)
if dy > dx * 1.5:
v_found = True
elif dx > dy * 1.5:
h_found = True
return v_found and h_found
def process(self, frame):
frame = cv2.flip(frame, 1)
h, w, _ = frame.shape
rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
hand_res = self.hands.process(rgb)
seg_res = self.segmentation.process(rgb)
mask = seg_res.segmentation_mask
# Trigger
if self.is_cross_seal(hand_res) and self.cooldown == 0:
self.clones_active = not self.clones_active
self.create_smoke_particles(h, w)
# 🔊 Play sound (prevent overlapping spam)
if not pygame.mixer.get_busy():
self.clone_sound.play()
self.cooldown = 30
if self.cooldown > 0:
self.cooldown -= 1
mask_hit = np.stack((mask,) * 3, axis=-1) > 0.3
person = np.where(mask_hit, frame, 0).astype(np.uint8)
output = frame.copy()
if self.clones_active:
for tx, ty, scale in self.layout:
M = np.float32([[scale, 0, tx], [0, scale, ty]])
c_img = cv2.warpAffine(person, M, (w, h))
c_mask = cv2.warpAffine(mask, M, (w, h))
c_hit = np.stack((c_mask,) * 3, axis=-1) > 0.1
output = np.where(c_hit, c_img, output)
output = np.where(mask_hit, frame, output)
# Animated Smoke
if self.smoke_timer > 0:
overlay = output.copy()
for p in self.particles:
cv2.circle(
overlay,
tuple(map(int, p['pos'])),
p['size'],
(p['color'], p['color'], p['color']),
-1
)
p['pos'][0] += p['v'][0]
p['pos'][1] += p['v'][1]
alpha = self.smoke_timer / 20.0
output = cv2.addWeighted(overlay, alpha, output, 1 - alpha, 0)
self.smoke_timer -= 1
return output
def run(self):
cap = cv2.VideoCapture(0)
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
cv2.imshow("Multi-Shadow Clone Jutsu", self.process(frame))
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
if __name__ == "__main__":
UltimateKageBunshin().run()