This commit is contained in:
Tulis
2025-09-10 19:51:05 +02:00
parent 5560f6b2e6
commit 5ab222aee3
4 changed files with 154 additions and 208 deletions

2
.idea/vcs.xml generated
View File

@ -2,7 +2,5 @@
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="$PROJECT_DIR$/mmdetection" vcs="Git" />
<mapping directory="$PROJECT_DIR$/mmpose" vcs="Git" />
</component>
</project>

112
.idea/workspace.xml generated
View File

@ -4,29 +4,11 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="441a4e7b-d6ce-44cb-92c5-2f22f1b1874f" name="Changes" comment="initial commit">
<change afterPath="$PROJECT_DIR$/.gitattributes" afterDir="false" />
<change afterPath="$PROJECT_DIR$/calculate.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/draw.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/filter.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/ploting.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/receive_images.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/receiver.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/sender.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/utils.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/video_methods.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/JustTwerk.iml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/JustTwerk.iml" afterDir="false" />
<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 beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/02_whole_body_from_image.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/body3d.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/hrnet_w48_coco_256x192-b9e0b3ab_20200708.pth" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/humanPoseDetection.ipynb" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/rtmdet_m_8xb32-100e_coco-obj365-person-235e8209.pth" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/rtmpose-m_simcc-body7_pt-body7_420e-256x192-e48f03d0_20230504.pth" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/test.py" beforeDir="false" afterPath="$PROJECT_DIR$/test.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/videopose_h36m_243frames_fullconv_supervised_cpn_ft-88f5abbb_20210527.pth" beforeDir="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" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -52,45 +34,46 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<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.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">{
&quot;keyToString&quot;: {
&quot;ModuleVcsDetector.initialDetectionPerformed&quot;: &quot;true&quot;,
&quot;Python.02_whole_body_from_image.executor&quot;: &quot;Run&quot;,
&quot;Python.3d.executor&quot;: &quot;Run&quot;,
&quot;Python.body3d.executor&quot;: &quot;Run&quot;,
&quot;Python.body3d_pose_lifter_demo.executor&quot;: &quot;Run&quot;,
&quot;Python.calculate.executor&quot;: &quot;Run&quot;,
&quot;Python.checkpoint.executor&quot;: &quot;Run&quot;,
&quot;Python.draw.executor&quot;: &quot;Run&quot;,
&quot;Python.filter.executor&quot;: &quot;Run&quot;,
&quot;Python.is_torch.executor&quot;: &quot;Run&quot;,
&quot;Python.local_visualizer_3d.executor&quot;: &quot;Run&quot;,
&quot;Python.main.executor&quot;: &quot;Run&quot;,
&quot;Python.openpose.executor&quot;: &quot;Run&quot;,
&quot;Python.receive_images.executor&quot;: &quot;Run&quot;,
&quot;Python.receiver.executor&quot;: &quot;Run&quot;,
&quot;Python.sender.executor&quot;: &quot;Run&quot;,
&quot;Python.test.executor&quot;: &quot;Run&quot;,
&quot;Python.ultralytics-test.executor&quot;: &quot;Run&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager.252&quot;: &quot;true&quot;,
&quot;RunOnceActivity.git.unshallow&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;main&quot;,
&quot;last_opened_file_path&quot;: &quot;C:/Users/Kajetan/PycharmProjects/JustTwerk&quot;,
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;configurable.group.editor&quot;,
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
}
}]]></component>
}</component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="C:\Users\Kajetan\PycharmProjects\JustTwerk" />
</key>
</component>
<component name="RunManager">
<component name="RunManager" selected="Python.draw">
<configuration name="draw" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="JustTwerk" />
<option name="ENV_FILES" value="" />
@ -166,7 +149,10 @@
<workItem from="1755891319108" duration="33842000" />
<workItem from="1755974689137" duration="258000" />
<workItem from="1755974961407" duration="19035000" />
<workItem from="1756053672258" duration="10010000" />
<workItem from="1756053672258" duration="16821000" />
<workItem from="1756216787734" duration="969000" />
<workItem from="1756632365037" duration="26000" />
<workItem from="1757522631129" duration="1771000" />
</task>
<task id="LOCAL-00001" summary="initial commit">
<option name="closed" value="true" />
@ -176,7 +162,15 @@
<option name="project" value="LOCAL" />
<updated>1755963464017</updated>
</task>
<option name="localTasksCounter" value="2" />
<task id="LOCAL-00002" summary="working">
<option name="closed" value="true" />
<created>1756143470328</created>
<option name="number" value="00002" />
<option name="presentableId" value="LOCAL-00002" />
<option name="project" value="LOCAL" />
<updated>1756143470328</updated>
</task>
<option name="localTasksCounter" value="3" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@ -184,9 +178,11 @@
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="initial commit" />
<option name="LAST_COMMIT_MESSAGE" value="initial commit" />
<MESSAGE value="working" />
<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$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" />

102
main.py
View File

@ -1,52 +1,23 @@
import pickle
import sys
import regex as re
import numpy as np
from ultralytics import YOLO
import cv2
import time
from calculate import normalize_pose, compare_poses_boolean
from draw import draw_new
from video_methods import initialize_method
model = YOLO("yolo11x-pose.pt")
if len(sys.argv) == 1:
method = sys.argv[1]
if len(sys.argv) == 2:
method_type = sys.argv[1]
else:
print("Podaj argument 'cam', albo 'network'.")
print("Podaj argument 'cam', albo 'net'.")
exit(1)
cap = cv2.VideoCapture(0)
if not cap.isOpened():
print("Nie można otworzyć kamerki")
exit(1)
last_time = time.time()
startTime = time.time()
stage = 0
pose = normalize_pose(np.array([[ 353.17, 107.28],
[ 363.3, 96.435],
[ 347.1, 98.647],
[ 390.12, 99.096],
[ 346.09, 103.63],
[ 425.77, 149.95],
[ 327.92, 153.12],
[ 495.16, 169.82],
[ 260.86, 166.3],
[ 565.53, 182.68],
[ 192.34, 170.58],
[ 393.83, 316.99],
[ 337.05, 316.41],
[ 388.36, 433.37],
[ 333.88, 431.89],
[ 383.58, 479.16],
[ 330.89, 480]]))
method = initialize_method(method_type)
do_pose_shot = False
@ -56,49 +27,33 @@ def click_event(event, x, y, flags, param):
if event == cv2.EVENT_LBUTTONDOWN: # lewy przycisk myszy
do_pose_shot = not do_pose_shot
currTimeIndex = 0
currIndex = None
currMove = None
currStatus = "Zacznij tanczyc"
def main():
last_time = time.time()
mehCount = 0
goodCount = 0
failCount = 0
failRate = 2
currTimeIndex = 0
currIndex = None
currMove = None
currStatus = "Zacznij tanczyc"
def wczytaj_dane_z_txt(sciezka):
wynik = []
with open(sciezka, "r") as f:
zawartosc = f.read()
mehCount = 0
goodCount = 0
failCount = 0
failRate = 2
# Znajdź wszystkie krotki w formacie (float, array([...]))
pattern = re.compile(r"\(([^,]+),\s*array\((\[.*?\]),\s*dtype=float32\)\)")
matches = pattern.findall(zawartosc)
moves = []
for m in matches:
liczba = float(m[0])
tablica = np.array(eval(m[1]), dtype=np.float32)
wynik.append((liczba, tablica))
return wynik
moves = []
with open('moves.pkl', 'rb') as f: # 'rb' = read binary
with open('moves.pkl', 'rb') as f: # 'rb' = read binary
moves = pickle.load(f)
startValue = moves[0][0]
totalCount = len(moves)
startValue = moves[0][0]
totalCount = len(moves)
for i, move in enumerate(moves):
for i, move in enumerate(moves):
moves[i] = (move[0] - startValue, move[1], move[2])
def find_closest(target):
global moves
return min(moves, key=lambda t: abs(t[0] - target))
while True:
frame = method.receive_frame()
while True:
ret, frame = cap.read()
frame = cv2.flip(frame, 1)
results = model(frame, verbose=False)
@ -124,7 +79,8 @@ while True:
if currTimeIndex != 0 and moves.index(find_closest(time.time() - currTimeIndex)) == len(moves) - 1:
mehCount = totalCount - failCount - goodCount
print(f"PODSUMOWANIE: FAIL {failCount} MEH: {mehCount} PERFECT: {goodCount} PERCENTAGE: {(goodCount + (0.95 * mehCount)) / totalCount * 100}%")
print(
f"PODSUMOWANIE: FAIL {failCount} MEH: {mehCount} PERFECT: {goodCount} PERCENTAGE: {(goodCount + (0.95 * mehCount)) / totalCount * 100}%")
exit(1)
if currMove is None:
@ -193,12 +149,4 @@ while True:
cv2.setMouseCallback('Klatka z kamerki', click_event)
cv2.waitKey(1) # Czekaj na naciśnięcie klawisza
# Access the results
for result in results:
annotated_frame = result.plot() # zwraca obraz z naniesionymi keypoints
# Wyświetlenie obrazu przy użyciu OpenCV
cv2.imshow("Pose", annotated_frame)
cv2.waitKey(0)
cv2.destroyAllWindows()
main()

View File

@ -10,6 +10,10 @@ def recvall(sock, n):
data += packet
return data
def find_closest(target):
global moves
return min(moves, key=lambda t: abs(t[0] - target))
def resize_with_padding(image, target_size=(640, 640)):
h, w = image.shape[:2]
target_w, target_h = target_size