fix: rotate head using better angles
This commit is contained in:
parent
3a35f3dcf8
commit
8a84863e30
1
.vscode/launch.json
vendored
1
.vscode/launch.json
vendored
|
@ -6,7 +6,6 @@
|
|||
"type": "python",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/src/main.py",
|
||||
// "program": "${workspaceFolder}/bite.py",
|
||||
"console": "integratedTerminal",
|
||||
"justMyCode": true,
|
||||
"env": {
|
||||
|
|
|
@ -31,4 +31,4 @@ class Crown:
|
|||
)
|
||||
|
||||
# draw texture
|
||||
blitRotate(screen, texture_scaled, crown_pos, self.env.angle)
|
||||
blitRotate(screen, texture_scaled, crown_pos, self.env.angle_x)
|
||||
|
|
|
@ -50,4 +50,4 @@ class Ear:
|
|||
)
|
||||
|
||||
# draw texture
|
||||
blitRotate(screen, texture_scaled, moustache_pos, self.env.angle, pivot)
|
||||
blitRotate(screen, texture_scaled, moustache_pos, self.env.angle_x, pivot)
|
||||
|
|
|
@ -26,9 +26,6 @@ class Head:
|
|||
head_top = landmark2vec(face_landmarks.landmark[LANDMARKS[1]], screen)
|
||||
head_bottom = landmark2vec(face_landmarks.landmark[LANDMARKS[3]], screen)
|
||||
|
||||
angle = (head_bottom - head_top).angle_to(pg.Vector2(0, 1))
|
||||
self.env.angle = angle
|
||||
|
||||
height = (head_bottom - head_top).length()
|
||||
ratio = self.texture.get_width() / self.texture.get_height()
|
||||
|
||||
|
@ -42,4 +39,4 @@ class Head:
|
|||
)
|
||||
|
||||
# draw texture
|
||||
blitRotate(screen, texture_scaled, head_pos, self.env.angle)
|
||||
blitRotate(screen, texture_scaled, head_pos, self.env.angle_x)
|
||||
|
|
|
@ -50,4 +50,4 @@ class Moustache:
|
|||
)
|
||||
|
||||
# draw texture
|
||||
blitRotate(screen, texture_scaled, moustache_pos, self.env.angle, pivot)
|
||||
blitRotate(screen, texture_scaled, moustache_pos, self.env.angle_x, pivot)
|
||||
|
|
|
@ -52,4 +52,4 @@ class Mouth:
|
|||
)
|
||||
|
||||
# draw texture
|
||||
blitRotate(screen, texture_scaled, mouth_pos, self.env.angle)
|
||||
blitRotate(screen, texture_scaled, mouth_pos, self.env.angle_x)
|
||||
|
|
|
@ -47,7 +47,6 @@ class Environment:
|
|||
) # type: ignore
|
||||
pg.display.set_caption("Projet APP")
|
||||
|
||||
self.angle = 0.0
|
||||
self.size = (0.0, 0.0)
|
||||
|
||||
# create body parts
|
||||
|
@ -141,7 +140,7 @@ class Environment:
|
|||
self.z.normalize_ip()
|
||||
|
||||
# print horizontal angle to screen
|
||||
self.angle_x = self.x.angle_to(pg.math.Vector3(1, 0, 0))
|
||||
self.angle_x = self.x.angle_to(pg.math.Vector3(0, 1, 0)) - 90
|
||||
self.angle_y = self.x.angle_to(pg.math.Vector3(0, 0, 1)) - 90
|
||||
self.angle_z = self.y.angle_to(pg.math.Vector3(0, 0, 1)) - 90
|
||||
|
||||
|
@ -195,8 +194,8 @@ class Environment:
|
|||
# )
|
||||
|
||||
# flip the image horizontally for a selfie-view display
|
||||
cv2.imshow("MediaPipe Face Mesh", self.frame)
|
||||
# cv2.imshow("MediaPipe Face Mesh", cv2.flip(self.frame, 1))
|
||||
# cv2.imshow("MediaPipe Face Mesh", self.frame)
|
||||
cv2.imshow("MediaPipe Face Mesh", cv2.flip(self.frame, 1))
|
||||
|
||||
def draw_avatar(self) -> None:
|
||||
"""Draw the avatar on the screen."""
|
||||
|
@ -205,7 +204,7 @@ class Environment:
|
|||
for part in self.body_parts.values():
|
||||
part.draw(self.screen)
|
||||
|
||||
self.screen.blit(self.screen, (0, 0))
|
||||
# self.screen.blit(pg.transform.flip(self.screen, True, False), (0, 0))
|
||||
# self.screen.blit(self.screen, (0, 0))
|
||||
self.screen.blit(pg.transform.flip(self.screen, True, False), (0, 0))
|
||||
|
||||
pg.display.flip()
|
||||
|
|
Loading…
Reference in a new issue