Compare commits
5 Commits
5ab222aee3
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 4943a20c11 | |||
| 40dc5b3b59 | |||
| 310997a8dd | |||
| d3063a6048 | |||
| 35e0f79b35 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,5 +4,6 @@
|
||||
/.gpu-3d/
|
||||
/.venv/
|
||||
/venv/
|
||||
*.mp4
|
||||
|
||||
yolo11*
|
||||
5
.idea/JustTwerk.iml
generated
5
.idea/JustTwerk.iml
generated
@ -2,9 +2,12 @@
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.gpu" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/.gpu-3d" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/.venv1" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/.venv-2" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3.14 virtualenv at C:\Users\Kajetan\PycharmProjects\JustTwerk\.venv-2" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="PyDocumentationSettings">
|
||||
|
||||
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@ -3,5 +3,5 @@
|
||||
<component name="Black">
|
||||
<option name="sdkName" value="Python 3.13 (JustTwerk)" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 virtualenv at C:\Users\Kajetan\PycharmProjects\JustTwerk\.gpu-3d" project-jdk-type="Python SDK" />
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.14 virtualenv at C:\Users\Kajetan\PycharmProjects\JustTwerk\.venv-2" project-jdk-type="Python SDK" />
|
||||
</project>
|
||||
138
.idea/workspace.xml
generated
138
.idea/workspace.xml
generated
@ -5,10 +5,13 @@
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="441a4e7b-d6ce-44cb-92c5-2f22f1b1874f" name="Changes" comment="working">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/vcs.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/moves_dump.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/JustTwerk.iml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/JustTwerk.iml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/utils.py" beforeDir="false" afterPath="$PROJECT_DIR$/utils.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/video_methods.py" beforeDir="false" afterPath="$PROJECT_DIR$/video_methods.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@ -34,46 +37,48 @@
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent">{
|
||||
"keyToString": {
|
||||
"ModuleVcsDetector.initialDetectionPerformed": "true",
|
||||
"Python.02_whole_body_from_image.executor": "Run",
|
||||
"Python.3d.executor": "Run",
|
||||
"Python.body3d.executor": "Run",
|
||||
"Python.body3d_pose_lifter_demo.executor": "Run",
|
||||
"Python.calculate.executor": "Run",
|
||||
"Python.checkpoint.executor": "Run",
|
||||
"Python.draw.executor": "Run",
|
||||
"Python.filter.executor": "Run",
|
||||
"Python.is_torch.executor": "Run",
|
||||
"Python.local_visualizer_3d.executor": "Run",
|
||||
"Python.main.executor": "Run",
|
||||
"Python.openpose.executor": "Run",
|
||||
"Python.receive_images.executor": "Run",
|
||||
"Python.receiver.executor": "Run",
|
||||
"Python.sender.executor": "Run",
|
||||
"Python.test.executor": "Run",
|
||||
"Python.ultralytics-test.executor": "Run",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager.252": "true",
|
||||
"RunOnceActivity.git.unshallow": "true",
|
||||
"git-widget-placeholder": "main",
|
||||
"last_opened_file_path": "C:/Users/Kajetan/PycharmProjects/JustTwerk",
|
||||
"node.js.detected.package.eslint": "true",
|
||||
"node.js.detected.package.tslint": "true",
|
||||
"node.js.selected.package.eslint": "(autodetect)",
|
||||
"node.js.selected.package.tslint": "(autodetect)",
|
||||
"nodejs_package_manager_path": "npm",
|
||||
"settings.editor.selected.configurable": "configurable.group.editor",
|
||||
"vue.rearranger.settings.migration": "true"
|
||||
<component name="PropertiesComponent"><![CDATA[{
|
||||
"keyToString": {
|
||||
"ModuleVcsDetector.initialDetectionPerformed": "true",
|
||||
"Python.02_whole_body_from_image.executor": "Run",
|
||||
"Python.3d.executor": "Run",
|
||||
"Python.body3d.executor": "Run",
|
||||
"Python.body3d_pose_lifter_demo.executor": "Run",
|
||||
"Python.calculate.executor": "Run",
|
||||
"Python.checkpoint.executor": "Run",
|
||||
"Python.draw.executor": "Run",
|
||||
"Python.filter.executor": "Run",
|
||||
"Python.is_torch.executor": "Run",
|
||||
"Python.local_visualizer_3d.executor": "Run",
|
||||
"Python.main.executor": "Run",
|
||||
"Python.moves_dump.executor": "Run",
|
||||
"Python.openpose.executor": "Run",
|
||||
"Python.receive_images.executor": "Run",
|
||||
"Python.receiver.executor": "Run",
|
||||
"Python.sender.executor": "Run",
|
||||
"Python.test.executor": "Run",
|
||||
"Python.ultralytics-test.executor": "Run",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager.252": "true",
|
||||
"RunOnceActivity.git.unshallow": "true",
|
||||
"git-widget-placeholder": "main",
|
||||
"ignore.virus.scanning.warn.message": "true",
|
||||
"last_opened_file_path": "C:/Users/Kajetan/PycharmProjects/JustTwerk",
|
||||
"node.js.detected.package.eslint": "true",
|
||||
"node.js.detected.package.tslint": "true",
|
||||
"node.js.selected.package.eslint": "(autodetect)",
|
||||
"node.js.selected.package.tslint": "(autodetect)",
|
||||
"nodejs_package_manager_path": "npm",
|
||||
"settings.editor.selected.configurable": "configurable.group.editor",
|
||||
"vue.rearranger.settings.migration": "true"
|
||||
}
|
||||
}</component>
|
||||
}]]></component>
|
||||
<component name="RecentsManager">
|
||||
<key name="CopyFile.RECENT_KEYS">
|
||||
<recent name="C:\Users\Kajetan\PycharmProjects\JustTwerk" />
|
||||
</key>
|
||||
</component>
|
||||
<component name="RunManager" selected="Python.draw">
|
||||
<component name="RunManager" selected="Python.main">
|
||||
<configuration name="draw" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
|
||||
<module name="JustTwerk" />
|
||||
<option name="ENV_FILES" value="" />
|
||||
@ -97,6 +102,29 @@
|
||||
<option name="INPUT_FILE" value="" />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
<configuration name="main" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
|
||||
<module name="JustTwerk" />
|
||||
<option name="ENV_FILES" value="" />
|
||||
<option name="INTERPRETER_OPTIONS" value="" />
|
||||
<option name="PARENT_ENVS" value="true" />
|
||||
<envs>
|
||||
<env name="PYTHONUNBUFFERED" value="1" />
|
||||
</envs>
|
||||
<option name="SDK_HOME" value="" />
|
||||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
|
||||
<option name="IS_MODULE_SDK" value="true" />
|
||||
<option name="ADD_CONTENT_ROOTS" value="true" />
|
||||
<option name="ADD_SOURCE_ROOTS" value="true" />
|
||||
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
|
||||
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/main.py" />
|
||||
<option name="PARAMETERS" value="cam" />
|
||||
<option name="SHOW_COMMAND_LINE" value="false" />
|
||||
<option name="EMULATE_TERMINAL" value="false" />
|
||||
<option name="MODULE_MODE" value="false" />
|
||||
<option name="REDIRECT_INPUT" value="false" />
|
||||
<option name="INPUT_FILE" value="" />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
<configuration name="test" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
|
||||
<module name="JustTwerk" />
|
||||
<option name="ENV_FILES" value="" />
|
||||
@ -122,6 +150,7 @@
|
||||
</configuration>
|
||||
<recent_temporary>
|
||||
<list>
|
||||
<item itemvalue="Python.main" />
|
||||
<item itemvalue="Python.draw" />
|
||||
<item itemvalue="Python.test" />
|
||||
</list>
|
||||
@ -130,8 +159,8 @@
|
||||
<component name="SharedIndexes">
|
||||
<attachedChunks>
|
||||
<set>
|
||||
<option value="bundled-js-predefined-d6986cc7102b-e03c56caf84a-JavaScript-PY-252.23892.515" />
|
||||
<option value="bundled-python-sdk-7e47963ff851-f0eec537fc84-com.jetbrains.pycharm.pro.sharedIndexes.bundled-PY-252.23892.515" />
|
||||
<option value="bundled-js-predefined-d6986cc7102b-3aa1da707db6-JavaScript-PY-252.27397.106" />
|
||||
<option value="bundled-python-sdk-4e2b1448bda8-9a97661f3031-com.jetbrains.pycharm.pro.sharedIndexes.bundled-PY-252.27397.106" />
|
||||
</set>
|
||||
</attachedChunks>
|
||||
</component>
|
||||
@ -152,7 +181,9 @@
|
||||
<workItem from="1756053672258" duration="16821000" />
|
||||
<workItem from="1756216787734" duration="969000" />
|
||||
<workItem from="1756632365037" duration="26000" />
|
||||
<workItem from="1757522631129" duration="1771000" />
|
||||
<workItem from="1757522631129" duration="3558000" />
|
||||
<workItem from="1764254526843" duration="634000" />
|
||||
<workItem from="1764255184384" duration="6392000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="initial commit">
|
||||
<option name="closed" value="true" />
|
||||
@ -170,7 +201,31 @@
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1756143470328</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="3" />
|
||||
<task id="LOCAL-00003" summary="working">
|
||||
<option name="closed" value="true" />
|
||||
<created>1757526666977</created>
|
||||
<option name="number" value="00003" />
|
||||
<option name="presentableId" value="LOCAL-00003" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1757526666977</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00004" summary="working">
|
||||
<option name="closed" value="true" />
|
||||
<created>1757526984452</created>
|
||||
<option name="number" value="00004" />
|
||||
<option name="presentableId" value="LOCAL-00004" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1757526984452</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00005" summary="working">
|
||||
<option name="closed" value="true" />
|
||||
<created>1757527150056</created>
|
||||
<option name="number" value="00005" />
|
||||
<option name="presentableId" value="LOCAL-00005" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1757527150056</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="6" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
@ -182,7 +237,7 @@
|
||||
<option name="LAST_COMMIT_MESSAGE" value="working" />
|
||||
</component>
|
||||
<component name="com.intellij.coverage.CoverageDataManagerImpl">
|
||||
<SUITE FILE_PATH="coverage/JustTwerk$main.coverage" NAME="main Coverage Results" MODIFIED="1756143599014" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
|
||||
<SUITE FILE_PATH="coverage/JustTwerk$main.coverage" NAME="main Coverage Results" MODIFIED="1764275198914" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
|
||||
<SUITE FILE_PATH="coverage/JustTwerk$receiver.coverage" NAME="receiver Coverage Results" MODIFIED="1756142451233" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
|
||||
<SUITE FILE_PATH="coverage/JustTwerk$filter.coverage" NAME="filter Coverage Results" MODIFIED="1755972211046" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
|
||||
<SUITE FILE_PATH="coverage/JustTwerk$body3d_pose_lifter_demo.coverage" NAME="body3d_pose_lifter_demo Coverage Results" MODIFIED="1755937235510" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/mmpose/demo" />
|
||||
@ -196,8 +251,9 @@
|
||||
<SUITE FILE_PATH="coverage/JustTwerk$draw.coverage" NAME="draw Coverage Results" MODIFIED="1756053706980" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
|
||||
<SUITE FILE_PATH="coverage/JustTwerk$ultralytics_test.coverage" NAME="ultralytics-test Coverage Results" MODIFIED="1756116377896" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
|
||||
<SUITE FILE_PATH="coverage/JustTwerk$3d.coverage" NAME="3d Coverage Results" MODIFIED="1756027604884" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
|
||||
<SUITE FILE_PATH="coverage/JustTwerk$moves_dump.coverage" NAME="moves_dump Coverage Results" MODIFIED="1764275034611" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
|
||||
<SUITE FILE_PATH="coverage/JustTwerk$local_visualizer_3d.coverage" NAME="local_visualizer_3d Coverage Results" MODIFIED="1755937454029" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/.gpu/Lib/site-packages/mmpose/visualization" />
|
||||
<SUITE FILE_PATH="coverage/JustTwerk$is_torch.coverage" NAME="is_torch Coverage Results" MODIFIED="1755943611769" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
|
||||
<SUITE FILE_PATH="coverage/JustTwerk$is_torch.coverage" NAME="is_torch Coverage Results" MODIFIED="1764256054151" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
|
||||
<SUITE FILE_PATH="coverage/JustTwerk$test.coverage" NAME="test Coverage Results" MODIFIED="1756025632346" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
|
||||
</component>
|
||||
</project>
|
||||
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"liveServer.settings.port": 5501
|
||||
}
|
||||
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()
|
||||
102
main.py
102
main.py
@ -5,11 +5,13 @@ from ultralytics import YOLO
|
||||
import cv2
|
||||
import time
|
||||
|
||||
import utils
|
||||
from calculate import normalize_pose, compare_poses_boolean
|
||||
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]
|
||||
@ -51,6 +53,8 @@ def main():
|
||||
for i, move in enumerate(moves):
|
||||
moves[i] = (move[0] - startValue, move[1], move[2])
|
||||
|
||||
print(moves)
|
||||
|
||||
while True:
|
||||
frame = method.receive_frame()
|
||||
|
||||
@ -65,72 +69,78 @@ def main():
|
||||
fps = 1 / delta if delta > 0 else float('inf')
|
||||
# print(f"\rDelta: {delta:.4f}s, FPS: {fps:.2f}", end="")
|
||||
|
||||
for result in results:
|
||||
kpts = result.keypoints.data[0] if len(result.keypoints.data) else None
|
||||
if len(results) == 0:
|
||||
continue
|
||||
|
||||
if kpts is None:
|
||||
continue
|
||||
result = results[0]
|
||||
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])
|
||||
cv2.imshow('you', draw_new(result.keypoints.xy.cpu()[0]))
|
||||
img = frame
|
||||
|
||||
if currTimeIndex != 0 and moves.index(find_closest(time.time() - currTimeIndex)) == len(moves) - 1:
|
||||
mehCount = totalCount - failCount - goodCount
|
||||
normalized = normalize_pose(result.keypoints.xy.cpu().numpy()[0])
|
||||
|
||||
print(
|
||||
f"PODSUMOWANIE: FAIL {failCount} MEH: {mehCount} PERFECT: {goodCount} PERCENTAGE: {(goodCount + (0.95 * mehCount)) / totalCount * 100}%")
|
||||
exit(1)
|
||||
draw = utils.normalize(result.keypoints.xy.cpu().numpy()[0])
|
||||
cv2.imshow('you', draw_new(draw * 100 + 100))
|
||||
|
||||
if currMove is None:
|
||||
if compare_poses_boolean(moves[0][1], normalized):
|
||||
currIndex = 1
|
||||
currTimeIndex = time.time()
|
||||
deltaTime = time.time()
|
||||
currStatus = f"Zaczoles tanczyc {currIndex}"
|
||||
currMove = moves[0]
|
||||
if currTimeIndex != 0 and moves.index(find_closest(moves, time.time() - currTimeIndex)) == len(moves) - 1:
|
||||
mehCount = totalCount - failCount - goodCount
|
||||
|
||||
# thread = Thread(target=print_animation, args=(moves, False))
|
||||
# thread.start()
|
||||
else:
|
||||
changed = False
|
||||
print(
|
||||
f"PODSUMOWANIE: FAIL {failCount} MEH: {mehCount} PERFECT: {goodCount} PERCENTAGE: {(goodCount + (0.95 * mehCount)) / totalCount * 100}%")
|
||||
exit(1)
|
||||
|
||||
closest = find_closest(time.time() - currTimeIndex)
|
||||
cv2.imshow('Dots', draw_new(closest[2]))
|
||||
if currMove is None:
|
||||
if compare_poses_boolean(moves[0][1], normalized):
|
||||
currIndex = 1
|
||||
currTimeIndex = time.time()
|
||||
deltaTime = time.time()
|
||||
currStatus = f"Zaczoles tanczyc {currIndex}"
|
||||
currMove = moves[0]
|
||||
|
||||
if abs((time.time() - currTimeIndex) - moves[currIndex][0]) > failRate:
|
||||
currStatus = f"FAIL!"
|
||||
failCount += 1
|
||||
# thread = Thread(target=print_animation, args=(moves, False))
|
||||
# thread.start()
|
||||
else:
|
||||
changed = False
|
||||
|
||||
if compare_poses_boolean(closest[1], normalized):
|
||||
# delays += (time.time() - deltaTime - moves[0][0]) * 1000
|
||||
# delaysCount += 1
|
||||
closest = find_closest(moves, time.time() - currTimeIndex)
|
||||
cv2.imshow('Dots', draw_new(closest[2]))
|
||||
|
||||
currStatus = f"SUPER! {currIndex} Zostalo {len(moves)} Delay {(time.time() - currTimeIndex - closest[0]) / 1000}ms"
|
||||
deltaTime = time.time()
|
||||
if abs((time.time() - currTimeIndex) - moves[currIndex][0]) > failRate:
|
||||
currStatus = f"FAIL!"
|
||||
failCount += 1
|
||||
|
||||
currIndex = moves.index(closest) + 1
|
||||
goodCount += 1
|
||||
changed = True
|
||||
if compare_poses_boolean(closest[1], normalized):
|
||||
# delays += (time.time() - deltaTime - moves[0][0]) * 1000
|
||||
# delaysCount += 1
|
||||
|
||||
if not changed and compare_poses_boolean(moves[currIndex][1], normalized):
|
||||
# delays += (time.time() - deltaTime - moves[0][0]) * 1000
|
||||
# delaysCount += 1
|
||||
currStatus = f"SUPER! {currIndex} Zostalo {len(moves)} Delay {(time.time() - currTimeIndex - closest[0]) / 1000}ms"
|
||||
deltaTime = time.time()
|
||||
|
||||
currStatus = f"SUPER! {currIndex} Zostalo {len(moves)} Delay {(time.time() - currTimeIndex - closest[0]) / 1000}ms"
|
||||
deltaTime = time.time()
|
||||
currIndex = moves.index(closest) + 1
|
||||
goodCount += 1
|
||||
changed = True
|
||||
|
||||
changed = True
|
||||
if not changed and compare_poses_boolean(moves[currIndex][1], normalized):
|
||||
# delays += (time.time() - deltaTime - moves[0][0]) * 1000
|
||||
# delaysCount += 1
|
||||
|
||||
currIndex += 1
|
||||
goodCount += 1
|
||||
currStatus = f"SUPER! {currIndex} Zostalo {len(moves)} Delay {(time.time() - currTimeIndex - closest[0]) / 1000}ms"
|
||||
deltaTime = time.time()
|
||||
|
||||
changed = True
|
||||
|
||||
currIndex += 1
|
||||
goodCount += 1
|
||||
|
||||
# if do_pose_shot:
|
||||
# moves.append((time.time() - startTime, normalize_pose(result.keypoints.xy.cpu().numpy()[0]), result.keypoints.xy.cpu()[0]))
|
||||
# elif len(moves) != 0:
|
||||
# with open('moves.pkl', 'wb') as f: # 'wb' = write binary
|
||||
# pickle.dump(moves, f)
|
||||
# pickle.dump
|
||||
# (moves, f)
|
||||
#
|
||||
# exit(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")
|
||||
42
moves_dump.py
Normal file
42
moves_dump.py
Normal file
@ -0,0 +1,42 @@
|
||||
import json
|
||||
import pickle
|
||||
import time
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
import utils
|
||||
from draw import draw_new
|
||||
|
||||
moves = []
|
||||
better_moves = {}
|
||||
|
||||
with open('moves.pkl', 'rb') as f: # 'rb' = read binary
|
||||
moves = pickle.load(f)
|
||||
|
||||
startValue = moves[0][0]
|
||||
totalCount = len(moves)
|
||||
|
||||
for i, move in enumerate(moves):
|
||||
moves[i] = (move[0] - startValue, move[1], move[2])
|
||||
|
||||
# left_hip = move[2][11] # Left Hip
|
||||
# right_hip = move[2][12] # Right Hip
|
||||
# center = (left_hip + right_hip) / 2
|
||||
#
|
||||
# # Normalizacja względem środka ciała
|
||||
# normalized_keypoints = move[2] - center
|
||||
#
|
||||
# better_moves[round((move[0] - startValue) * 1000)] = normalized_keypoints.tolist()
|
||||
#
|
||||
# # scale = utils.distance(move[2][11], move[2][12])
|
||||
# # print(scale)
|
||||
# draw = normalized_keypoints + 200
|
||||
|
||||
|
||||
# Do rysowania (np. przesunięcie na ekran)
|
||||
draw = utils.normalize(move[2]) * 200 + 250
|
||||
|
||||
cv2.imshow('you', draw_new(draw))
|
||||
cv2.waitKey(1)
|
||||
time.sleep(0.1)
|
||||
30
utils.py
30
utils.py
@ -1,3 +1,5 @@
|
||||
import math
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
@ -10,8 +12,32 @@ def recvall(sock, n):
|
||||
data += packet
|
||||
return data
|
||||
|
||||
def find_closest(target):
|
||||
global moves
|
||||
def distance(p1, p2):
|
||||
return math.sqrt((p2[0] - p1[0])**2 + (p2[1] - p1[1])**2)
|
||||
|
||||
import numpy as np
|
||||
|
||||
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
|
||||
|
||||
# Przesunięcie względem środka
|
||||
normalized_keypoints = move - center
|
||||
|
||||
# Zamiast max_dist używamy stałej miary "rozmiaru ciała"
|
||||
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]
|
||||
return draw
|
||||
|
||||
def find_closest(moves, target):
|
||||
return min(moves, key=lambda t: abs(t[0] - target))
|
||||
|
||||
def resize_with_padding(image, target_size=(640, 640)):
|
||||
|
||||
@ -16,7 +16,7 @@ class Method:
|
||||
def __init__(self, method_type):
|
||||
self.method_type = method_type
|
||||
|
||||
if method_type is "cam":
|
||||
if method_type == "cam":
|
||||
self.cap = cv2.VideoCapture(0)
|
||||
|
||||
if not self.cap.isOpened():
|
||||
@ -34,7 +34,7 @@ class Method:
|
||||
self.start_time = time.time()
|
||||
|
||||
def receive_frame(self):
|
||||
if self.method_type is "cam":
|
||||
if self.method_type == "cam":
|
||||
_, frame = self.cap.read()
|
||||
|
||||
if not _:
|
||||
|
||||
Reference in New Issue
Block a user