horrible wavy animation pleazse burn this
This commit is contained in:
parent
61c6baed4f
commit
ff99203af6
|
@ -18,6 +18,7 @@ class BodyPart:
|
||||||
image_path: str,
|
image_path: str,
|
||||||
position: np.ndarray,
|
position: np.ndarray,
|
||||||
height: float,
|
height: float,
|
||||||
|
wavy=None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the part."""
|
"""Initialize the part."""
|
||||||
self.env = env
|
self.env = env
|
||||||
|
@ -50,6 +51,8 @@ class BodyPart:
|
||||||
dtype=np.float32,
|
dtype=np.float32,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.wavy = wavy
|
||||||
|
|
||||||
def draw(self) -> None:
|
def draw(self) -> None:
|
||||||
"""Draw the part on the screen."""
|
"""Draw the part on the screen."""
|
||||||
# compute position
|
# compute position
|
||||||
|
@ -85,6 +88,23 @@ class BodyPart:
|
||||||
self.env.frame.shape[1::-1],
|
self.env.frame.shape[1::-1],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if self.wavy:
|
||||||
|
# move left side of bounding box up and down sinusoidally
|
||||||
|
self.sin_box = self.wavy(bounding_box.copy(), self.env.frame_count)
|
||||||
|
|
||||||
|
# compute affine transform
|
||||||
|
sin_mat = cv2.getAffineTransform(
|
||||||
|
bounding_box[[0, 1, 3]].astype(np.float32),
|
||||||
|
self.sin_box[[0, 1, 3]].astype(np.float32),
|
||||||
|
)
|
||||||
|
|
||||||
|
# apply affine transform to image
|
||||||
|
warped = cv2.warpAffine(
|
||||||
|
warped,
|
||||||
|
sin_mat,
|
||||||
|
self.env.frame.shape[1::-1],
|
||||||
|
)
|
||||||
|
|
||||||
# replace non black pixels of warped image by frame
|
# replace non black pixels of warped image by frame
|
||||||
self.env.avatar[warped[:, :, 3] != 0] = warped[warped[:, :, 3] != 0][:, :3]
|
self.env.avatar[warped[:, :, 3] != 0] = warped[warped[:, :, 3] != 0][:, :3]
|
||||||
|
|
||||||
|
@ -97,3 +117,11 @@ class BodyPart:
|
||||||
(255, 255, 255),
|
(255, 255, 255),
|
||||||
2,
|
2,
|
||||||
)
|
)
|
||||||
|
if self.wavy:
|
||||||
|
cv2.polylines(
|
||||||
|
self.env.frame,
|
||||||
|
[self.sin_box.squeeze().astype(int)],
|
||||||
|
True,
|
||||||
|
(0, 0, 255),
|
||||||
|
2,
|
||||||
|
)
|
||||||
|
|
|
@ -12,6 +12,30 @@ NOSE_LANDMARK = 4
|
||||||
UNREFINED_LANDMARKS = 468
|
UNREFINED_LANDMARKS = 468
|
||||||
|
|
||||||
|
|
||||||
|
def earL_wavy(box, t):
|
||||||
|
box[0, 0, 0] -= np.sin(t / 7) * 11
|
||||||
|
box[1, 0, 0] -= np.sin(t / 7) * 11
|
||||||
|
return box
|
||||||
|
|
||||||
|
|
||||||
|
def earR_wavy(box, t):
|
||||||
|
box[0, 0, 0] += np.sin(t / 7 + 1) * 11
|
||||||
|
box[1, 0, 0] += np.sin(t / 7 + 1) * 11
|
||||||
|
return box
|
||||||
|
|
||||||
|
|
||||||
|
def moustacheL_wavy(box, t):
|
||||||
|
box[0, 0, 1] += np.sin(t / 7) * 11
|
||||||
|
box[3, 0, 1] += np.sin(t / 7) * 11
|
||||||
|
return box
|
||||||
|
|
||||||
|
|
||||||
|
def moustacheR_wavy(box, t):
|
||||||
|
box[1, 0, 1] += np.sin(t / 7 + 1) * 11
|
||||||
|
box[2, 0, 1] += np.sin(t / 7 + 1) * 11
|
||||||
|
return box
|
||||||
|
|
||||||
|
|
||||||
class Environment:
|
class Environment:
|
||||||
"""The environment is the main class of the application.
|
"""The environment is the main class of the application.
|
||||||
|
|
||||||
|
@ -26,6 +50,8 @@ class Environment:
|
||||||
# store reference to webcam
|
# store reference to webcam
|
||||||
self.cam = camera
|
self.cam = camera
|
||||||
|
|
||||||
|
self.frame_count = 0
|
||||||
|
|
||||||
# mediapipe stuff
|
# mediapipe stuff
|
||||||
self.mp_drawing = mp.solutions.drawing_utils # type: ignore
|
self.mp_drawing = mp.solutions.drawing_utils # type: ignore
|
||||||
self.mp_drawing_styles = mp.solutions.drawing_styles # type: ignore
|
self.mp_drawing_styles = mp.solutions.drawing_styles # type: ignore
|
||||||
|
@ -48,12 +74,14 @@ class Environment:
|
||||||
"assets/earL.png",
|
"assets/earL.png",
|
||||||
np.array([6, 11, -0.5]),
|
np.array([6, 11, -0.5]),
|
||||||
1,
|
1,
|
||||||
|
wavy=earL_wavy,
|
||||||
),
|
),
|
||||||
BodyPart(
|
BodyPart(
|
||||||
self,
|
self,
|
||||||
"assets/earR.png",
|
"assets/earR.png",
|
||||||
np.array([-6, 11, -0.5]),
|
np.array([-6, 11, -0.5]),
|
||||||
1,
|
1,
|
||||||
|
wavy=earR_wavy,
|
||||||
),
|
),
|
||||||
BodyPart(
|
BodyPart(
|
||||||
self,
|
self,
|
||||||
|
@ -66,12 +94,14 @@ class Environment:
|
||||||
"assets/moustacheL.png",
|
"assets/moustacheL.png",
|
||||||
np.array([13, -6, 0.1]),
|
np.array([13, -6, 0.1]),
|
||||||
1,
|
1,
|
||||||
|
wavy=moustacheL_wavy,
|
||||||
),
|
),
|
||||||
BodyPart(
|
BodyPart(
|
||||||
self,
|
self,
|
||||||
"assets/moustacheR.png",
|
"assets/moustacheR.png",
|
||||||
np.array([-13, -6, 0.1]),
|
np.array([-13, -6, 0.1]),
|
||||||
1,
|
1,
|
||||||
|
wavy=moustacheR_wavy,
|
||||||
),
|
),
|
||||||
ActiveBodyPart(
|
ActiveBodyPart(
|
||||||
self,
|
self,
|
||||||
|
@ -136,6 +166,8 @@ class Environment:
|
||||||
logging.debug("Ignoring empty camera frame.")
|
logging.debug("Ignoring empty camera frame.")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
self.frame_count += 1
|
||||||
|
|
||||||
# detect keypoints on frame
|
# detect keypoints on frame
|
||||||
self.detect_keypoints()
|
self.detect_keypoints()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue