working
This commit is contained in:
BIN
__pycache__/draw.cpython-312.pyc
Normal file
BIN
__pycache__/draw.cpython-312.pyc
Normal file
Binary file not shown.
BIN
__pycache__/filter.cpython-312.pyc
Normal file
BIN
__pycache__/filter.cpython-312.pyc
Normal file
Binary file not shown.
BIN
__pycache__/utils.cpython-312.pyc
Normal file
BIN
__pycache__/utils.cpython-312.pyc
Normal file
Binary file not shown.
36
mac.py
Normal file
36
mac.py
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import cv2
|
||||||
|
import mediapipe as mp
|
||||||
|
mp_drawing = mp.solutions.drawing_utils
|
||||||
|
mp_drawing_styles = mp.solutions.drawing_styles
|
||||||
|
mp_pose = mp.solutions.pose
|
||||||
|
|
||||||
|
cap = cv2.VideoCapture(0)
|
||||||
|
with mp_pose.Pose(
|
||||||
|
min_detection_confidence=0.5,
|
||||||
|
min_tracking_confidence=0.5) as pose:
|
||||||
|
while cap.isOpened():
|
||||||
|
success, image = cap.read()
|
||||||
|
if not success:
|
||||||
|
print("Ignoring empty camera frame.")
|
||||||
|
continue
|
||||||
|
|
||||||
|
# To improve performance, optionally mark the image as not writeable to
|
||||||
|
# pass by reference.
|
||||||
|
image.flags.writeable = False
|
||||||
|
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
||||||
|
results = pose.process(image)
|
||||||
|
|
||||||
|
# Draw the pose annotation on the image.
|
||||||
|
image.flags.writeable = True
|
||||||
|
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
|
||||||
|
mp_drawing.draw_landmarks(
|
||||||
|
image,
|
||||||
|
results.pose_landmarks,
|
||||||
|
mp_pose.POSE_CONNECTIONS,
|
||||||
|
landmark_drawing_spec=mp_drawing_styles.get_default_pose_landmarks_style())
|
||||||
|
# Flip the image horizontally for a selfie-view display.
|
||||||
|
cv2.imshow('MediaPipe Pose', cv2.flip(image, 1))
|
||||||
|
if cv2.waitKey(5) & 0xFF == 27:
|
||||||
|
break
|
||||||
|
|
||||||
|
cap.release()
|
||||||
93
main.py
93
main.py
@ -69,68 +69,71 @@ def main():
|
|||||||
fps = 1 / delta if delta > 0 else float('inf')
|
fps = 1 / delta if delta > 0 else float('inf')
|
||||||
# print(f"\rDelta: {delta:.4f}s, FPS: {fps:.2f}", end="")
|
# print(f"\rDelta: {delta:.4f}s, FPS: {fps:.2f}", end="")
|
||||||
|
|
||||||
for result in results:
|
if len(results) == 0:
|
||||||
kpts = result.keypoints.data[0] if len(result.keypoints.data) else None
|
continue
|
||||||
|
|
||||||
if kpts is None:
|
result = results[0]
|
||||||
continue
|
kpts = result.keypoints.data[0] if len(result.keypoints.data) else None
|
||||||
|
|
||||||
img = frame
|
if kpts is None:
|
||||||
|
continue
|
||||||
|
|
||||||
normalized = normalize_pose(result.keypoints.xy.cpu().numpy()[0])
|
img = frame
|
||||||
|
|
||||||
draw = utils.normalize(result.keypoints.xy.cpu().numpy()[0])
|
normalized = normalize_pose(result.keypoints.xy.cpu().numpy()[0])
|
||||||
cv2.imshow('you', draw_new(draw * 100 + 100))
|
|
||||||
|
|
||||||
if currTimeIndex != 0 and moves.index(find_closest(moves, time.time() - currTimeIndex)) == len(moves) - 1:
|
draw = utils.normalize(result.keypoints.xy.cpu().numpy()[0])
|
||||||
mehCount = totalCount - failCount - goodCount
|
cv2.imshow('you', draw_new(draw * 100 + 100))
|
||||||
|
|
||||||
print(
|
if currTimeIndex != 0 and moves.index(find_closest(moves, time.time() - currTimeIndex)) == len(moves) - 1:
|
||||||
f"PODSUMOWANIE: FAIL {failCount} MEH: {mehCount} PERFECT: {goodCount} PERCENTAGE: {(goodCount + (0.95 * mehCount)) / totalCount * 100}%")
|
mehCount = totalCount - failCount - goodCount
|
||||||
exit(1)
|
|
||||||
|
|
||||||
if currMove is None:
|
print(
|
||||||
if compare_poses_boolean(moves[0][1], normalized):
|
f"PODSUMOWANIE: FAIL {failCount} MEH: {mehCount} PERFECT: {goodCount} PERCENTAGE: {(goodCount + (0.95 * mehCount)) / totalCount * 100}%")
|
||||||
currIndex = 1
|
exit(1)
|
||||||
currTimeIndex = time.time()
|
|
||||||
deltaTime = time.time()
|
|
||||||
currStatus = f"Zaczoles tanczyc {currIndex}"
|
|
||||||
currMove = moves[0]
|
|
||||||
|
|
||||||
# thread = Thread(target=print_animation, args=(moves, False))
|
if currMove is None:
|
||||||
# thread.start()
|
if compare_poses_boolean(moves[0][1], normalized):
|
||||||
else:
|
currIndex = 1
|
||||||
changed = False
|
currTimeIndex = time.time()
|
||||||
|
deltaTime = time.time()
|
||||||
|
currStatus = f"Zaczoles tanczyc {currIndex}"
|
||||||
|
currMove = moves[0]
|
||||||
|
|
||||||
closest = find_closest(moves, time.time() - currTimeIndex)
|
# thread = Thread(target=print_animation, args=(moves, False))
|
||||||
cv2.imshow('Dots', draw_new(closest[2]))
|
# thread.start()
|
||||||
|
else:
|
||||||
|
changed = False
|
||||||
|
|
||||||
if abs((time.time() - currTimeIndex) - moves[currIndex][0]) > failRate:
|
closest = find_closest(moves, time.time() - currTimeIndex)
|
||||||
currStatus = f"FAIL!"
|
cv2.imshow('Dots', draw_new(closest[2]))
|
||||||
failCount += 1
|
|
||||||
|
|
||||||
if compare_poses_boolean(closest[1], normalized):
|
if abs((time.time() - currTimeIndex) - moves[currIndex][0]) > failRate:
|
||||||
# delays += (time.time() - deltaTime - moves[0][0]) * 1000
|
currStatus = f"FAIL!"
|
||||||
# delaysCount += 1
|
failCount += 1
|
||||||
|
|
||||||
currStatus = f"SUPER! {currIndex} Zostalo {len(moves)} Delay {(time.time() - currTimeIndex - closest[0]) / 1000}ms"
|
if compare_poses_boolean(closest[1], normalized):
|
||||||
deltaTime = time.time()
|
# delays += (time.time() - deltaTime - moves[0][0]) * 1000
|
||||||
|
# delaysCount += 1
|
||||||
|
|
||||||
currIndex = moves.index(closest) + 1
|
currStatus = f"SUPER! {currIndex} Zostalo {len(moves)} Delay {(time.time() - currTimeIndex - closest[0]) / 1000}ms"
|
||||||
goodCount += 1
|
deltaTime = time.time()
|
||||||
changed = True
|
|
||||||
|
|
||||||
if not changed and compare_poses_boolean(moves[currIndex][1], normalized):
|
currIndex = moves.index(closest) + 1
|
||||||
# delays += (time.time() - deltaTime - moves[0][0]) * 1000
|
goodCount += 1
|
||||||
# delaysCount += 1
|
changed = True
|
||||||
|
|
||||||
currStatus = f"SUPER! {currIndex} Zostalo {len(moves)} Delay {(time.time() - currTimeIndex - closest[0]) / 1000}ms"
|
if not changed and compare_poses_boolean(moves[currIndex][1], normalized):
|
||||||
deltaTime = time.time()
|
# delays += (time.time() - deltaTime - moves[0][0]) * 1000
|
||||||
|
# delaysCount += 1
|
||||||
|
|
||||||
changed = True
|
currStatus = f"SUPER! {currIndex} Zostalo {len(moves)} Delay {(time.time() - currTimeIndex - closest[0]) / 1000}ms"
|
||||||
|
deltaTime = time.time()
|
||||||
|
|
||||||
currIndex += 1
|
changed = True
|
||||||
goodCount += 1
|
|
||||||
|
currIndex += 1
|
||||||
|
goodCount += 1
|
||||||
|
|
||||||
# if do_pose_shot:
|
# if do_pose_shot:
|
||||||
# moves.append((time.time() - startTime, normalize_pose(result.keypoints.xy.cpu().numpy()[0]), result.keypoints.xy.cpu()[0]))
|
# moves.append((time.time() - startTime, normalize_pose(result.keypoints.xy.cpu().numpy()[0]), result.keypoints.xy.cpu()[0]))
|
||||||
|
|||||||
@ -35,7 +35,7 @@ for i, move in enumerate(moves):
|
|||||||
|
|
||||||
|
|
||||||
# Do rysowania (np. przesunięcie na ekran)
|
# Do rysowania (np. przesunięcie na ekran)
|
||||||
draw = utils.normalize(move[2])
|
draw = utils.normalize(move[2]) * 200 + 250
|
||||||
|
|
||||||
cv2.imshow('you', draw_new(draw))
|
cv2.imshow('you', draw_new(draw))
|
||||||
cv2.waitKey(1)
|
cv2.waitKey(1)
|
||||||
|
|||||||
21
utils.py
21
utils.py
@ -15,21 +15,26 @@ def recvall(sock, n):
|
|||||||
def distance(p1, p2):
|
def distance(p1, p2):
|
||||||
return math.sqrt((p2[0] - p1[0])**2 + (p2[1] - p1[1])**2)
|
return math.sqrt((p2[0] - p1[0])**2 + (p2[1] - p1[1])**2)
|
||||||
|
|
||||||
def normalize(move):
|
import numpy as np
|
||||||
left_hip = move[11] # Left Hip
|
|
||||||
right_hip = move[12] # Right Hip
|
|
||||||
|
|
||||||
|
def normalize(move):
|
||||||
|
left_hip = move[11] # Left Hip
|
||||||
|
right_hip = move[12] # Right Hip
|
||||||
|
nose = move[0] # Nose (głowa)
|
||||||
|
|
||||||
|
# Środek bioder
|
||||||
center = (left_hip + right_hip) / 2
|
center = (left_hip + right_hip) / 2
|
||||||
|
|
||||||
|
# Przesunięcie względem środka
|
||||||
normalized_keypoints = move - center
|
normalized_keypoints = move - center
|
||||||
distances = np.linalg.norm(normalized_keypoints[:, :2], axis=1)
|
|
||||||
max_dist = np.max(distances)
|
|
||||||
|
|
||||||
if max_dist > 0:
|
# Zamiast max_dist używamy stałej miary "rozmiaru ciała"
|
||||||
normalized_keypoints[:, :2] /= max_dist
|
body_height = np.linalg.norm(nose[:2] - center[:2]) # np. odległość biodra-głowa
|
||||||
|
|
||||||
|
if body_height > 0:
|
||||||
|
normalized_keypoints[:, :2] /= body_height
|
||||||
|
|
||||||
draw = normalized_keypoints[:, :2]
|
draw = normalized_keypoints[:, :2]
|
||||||
|
|
||||||
return draw
|
return draw
|
||||||
|
|
||||||
def find_closest(moves, target):
|
def find_closest(moves, target):
|
||||||
|
|||||||
Reference in New Issue
Block a user