working
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,5 +4,6 @@
|
||||
/.gpu-3d/
|
||||
/.venv/
|
||||
/venv/
|
||||
*.mp4
|
||||
|
||||
yolo11*
|
||||
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"liveServer.settings.port": 5501
|
||||
}
|
||||
2
main.py
2
main.py
@ -11,7 +11,7 @@ from draw import draw_new
|
||||
from utils import find_closest
|
||||
from video_methods import initialize_method
|
||||
|
||||
model = YOLO("yolo11x-pose.pt")
|
||||
model = YOLO("yolo11s-pose.pt")
|
||||
|
||||
if len(sys.argv) == 2:
|
||||
method_type = sys.argv[1]
|
||||
|
||||
43
moves_3d.py
Normal file
43
moves_3d.py
Normal file
@ -0,0 +1,43 @@
|
||||
import cv2
|
||||
import mediapipe as mp
|
||||
import cv2
|
||||
import mediapipe as mp
|
||||
import matplotlib.pyplot as plt
|
||||
from mpl_toolkits.mplot3d import Axes3D
|
||||
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.")
|
||||
# If loading a video, use 'break' instead of 'continue'.
|
||||
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)
|
||||
|
||||
print(f"\r{results.pose_world_landmarks[0]}", end="")
|
||||
|
||||
# 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.
|
||||
|
||||
landmarks = results.pose_world_landmarks.landmark
|
||||
|
||||
print(landmark)
|
||||
cap.release()
|
||||
92
moves_3d_mp4.py
Normal file
92
moves_3d_mp4.py
Normal file
@ -0,0 +1,92 @@
|
||||
import cv2
|
||||
import mediapipe as mp
|
||||
import matplotlib
|
||||
matplotlib.use("Agg") # <-- ważne: wyłącza GUI
|
||||
import matplotlib.pyplot as plt
|
||||
from mpl_toolkits.mplot3d import Axes3D
|
||||
import numpy as np
|
||||
|
||||
# ---------------------
|
||||
# Wideo wejściowe
|
||||
# ---------------------
|
||||
cap = cv2.VideoCapture("input.mp4")
|
||||
fps = cap.get(cv2.CAP_PROP_FPS)
|
||||
width = 640
|
||||
height = 640
|
||||
|
||||
# ---------------------
|
||||
# Wideo wyjściowe
|
||||
# ---------------------
|
||||
fourcc = cv2.VideoWriter_fourcc(*"MJPG")
|
||||
|
||||
|
||||
out = cv2.VideoWriter("output.mp4", fourcc, fps, (width, height))
|
||||
|
||||
# ---------------------
|
||||
# MediaPipe Pose
|
||||
# ---------------------
|
||||
mp_pose = mp.solutions.pose
|
||||
pose = mp_pose.Pose(static_image_mode=False, model_complexity=1)
|
||||
|
||||
frame_id = 0
|
||||
|
||||
while True:
|
||||
ok, frame = cap.read()
|
||||
if not ok:
|
||||
break
|
||||
|
||||
rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
||||
results = pose.process(rgb)
|
||||
|
||||
# -----------------------------------------
|
||||
# 3D landmarki: pose_world_landmarks
|
||||
# -----------------------------------------
|
||||
if results.pose_world_landmarks:
|
||||
lm = results.pose_world_landmarks.landmark
|
||||
|
||||
xs = np.array([p.x for p in lm])
|
||||
ys = np.array([p.y for p in lm])
|
||||
zs = np.array([p.z for p in lm])
|
||||
|
||||
# -----------------------------
|
||||
# RYSOWANIE 3D w Matplotlib
|
||||
# -----------------------------
|
||||
fig = plt.figure(figsize=(6.4, 6.4), dpi=100)
|
||||
ax = fig.add_subplot(111, projection="3d")
|
||||
|
||||
ax.scatter(xs, zs, ys, s=20)
|
||||
|
||||
ax.set_xlim([-1, 1])
|
||||
ax.set_ylim([-1, 1])
|
||||
ax.set_zlim([-1, 1])
|
||||
|
||||
ax.set_xlabel("X")
|
||||
ax.set_ylabel("Y")
|
||||
ax.set_zlabel("Z")
|
||||
ax.invert_zaxis()
|
||||
|
||||
# -----------------------------------------
|
||||
# Konwersja wykresu Matplotlib → klatka do MP4
|
||||
# -----------------------------------------
|
||||
fig.canvas.draw()
|
||||
renderer = fig.canvas.get_renderer()
|
||||
|
||||
w, h = fig.canvas.get_width_height()
|
||||
|
||||
buf = renderer.buffer_rgba()
|
||||
plot_img = np.frombuffer(buf, dtype=np.uint8).reshape((h, w, 4))[:, :, :3]
|
||||
|
||||
|
||||
plt.close(fig)
|
||||
|
||||
# Dopasowanie rozmiaru do wideo
|
||||
plot_img = cv2.resize(plot_img, (width, height))
|
||||
plot_img = cv2.cvtColor(plot_img, cv2.COLOR_RGB2BGR)
|
||||
|
||||
out.write(plot_img)
|
||||
|
||||
frame_id += 1
|
||||
|
||||
cap.release()
|
||||
out.release()
|
||||
print("Zapisano: output.mp4")
|
||||
Reference in New Issue
Block a user