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"> <project version="4">
<component name="VcsDirectoryMappings"> <component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" /> <mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="$PROJECT_DIR$/mmdetection" vcs="Git" />
<mapping directory="$PROJECT_DIR$/mmpose" vcs="Git" />
</component> </component>
</project> </project>

112
.idea/workspace.xml generated
View File

@ -4,29 +4,11 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="441a4e7b-d6ce-44cb-92c5-2f22f1b1874f" name="Changes" comment="initial commit"> <list default="true" id="441a4e7b-d6ce-44cb-92c5-2f22f1b1874f" name="Changes" comment="working">
<change afterPath="$PROJECT_DIR$/.gitattributes" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/vcs.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/vcs.xml" 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" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.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$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/body3d.py" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/utils.py" beforeDir="false" afterPath="$PROJECT_DIR$/utils.py" afterDir="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" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -52,45 +34,46 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent"><![CDATA[{ <component name="PropertiesComponent">{
"keyToString": { &quot;keyToString&quot;: {
"ModuleVcsDetector.initialDetectionPerformed": "true", &quot;ModuleVcsDetector.initialDetectionPerformed&quot;: &quot;true&quot;,
"Python.02_whole_body_from_image.executor": "Run", &quot;Python.02_whole_body_from_image.executor&quot;: &quot;Run&quot;,
"Python.3d.executor": "Run", &quot;Python.3d.executor&quot;: &quot;Run&quot;,
"Python.body3d.executor": "Run", &quot;Python.body3d.executor&quot;: &quot;Run&quot;,
"Python.body3d_pose_lifter_demo.executor": "Run", &quot;Python.body3d_pose_lifter_demo.executor&quot;: &quot;Run&quot;,
"Python.calculate.executor": "Run", &quot;Python.calculate.executor&quot;: &quot;Run&quot;,
"Python.checkpoint.executor": "Run", &quot;Python.checkpoint.executor&quot;: &quot;Run&quot;,
"Python.draw.executor": "Run", &quot;Python.draw.executor&quot;: &quot;Run&quot;,
"Python.filter.executor": "Run", &quot;Python.filter.executor&quot;: &quot;Run&quot;,
"Python.is_torch.executor": "Run", &quot;Python.is_torch.executor&quot;: &quot;Run&quot;,
"Python.local_visualizer_3d.executor": "Run", &quot;Python.local_visualizer_3d.executor&quot;: &quot;Run&quot;,
"Python.openpose.executor": "Run", &quot;Python.main.executor&quot;: &quot;Run&quot;,
"Python.receive_images.executor": "Run", &quot;Python.openpose.executor&quot;: &quot;Run&quot;,
"Python.receiver.executor": "Run", &quot;Python.receive_images.executor&quot;: &quot;Run&quot;,
"Python.sender.executor": "Run", &quot;Python.receiver.executor&quot;: &quot;Run&quot;,
"Python.test.executor": "Run", &quot;Python.sender.executor&quot;: &quot;Run&quot;,
"Python.ultralytics-test.executor": "Run", &quot;Python.test.executor&quot;: &quot;Run&quot;,
"RunOnceActivity.ShowReadmeOnStart": "true", &quot;Python.ultralytics-test.executor&quot;: &quot;Run&quot;,
"RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager.252": "true", &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
"RunOnceActivity.git.unshallow": "true", &quot;RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager.252&quot;: &quot;true&quot;,
"git-widget-placeholder": "main", &quot;RunOnceActivity.git.unshallow&quot;: &quot;true&quot;,
"last_opened_file_path": "C:/Users/Kajetan/PycharmProjects/JustTwerk", &quot;git-widget-placeholder&quot;: &quot;main&quot;,
"node.js.detected.package.eslint": "true", &quot;last_opened_file_path&quot;: &quot;C:/Users/Kajetan/PycharmProjects/JustTwerk&quot;,
"node.js.detected.package.tslint": "true", &quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
"node.js.selected.package.eslint": "(autodetect)", &quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
"node.js.selected.package.tslint": "(autodetect)", &quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
"nodejs_package_manager_path": "npm", &quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
"settings.editor.selected.configurable": "configurable.group.editor", &quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
"vue.rearranger.settings.migration": "true" &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"> <component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS"> <key name="CopyFile.RECENT_KEYS">
<recent name="C:\Users\Kajetan\PycharmProjects\JustTwerk" /> <recent name="C:\Users\Kajetan\PycharmProjects\JustTwerk" />
</key> </key>
</component> </component>
<component name="RunManager"> <component name="RunManager" selected="Python.draw">
<configuration name="draw" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true"> <configuration name="draw" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="JustTwerk" /> <module name="JustTwerk" />
<option name="ENV_FILES" value="" /> <option name="ENV_FILES" value="" />
@ -166,7 +149,10 @@
<workItem from="1755891319108" duration="33842000" /> <workItem from="1755891319108" duration="33842000" />
<workItem from="1755974689137" duration="258000" /> <workItem from="1755974689137" duration="258000" />
<workItem from="1755974961407" duration="19035000" /> <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>
<task id="LOCAL-00001" summary="initial commit"> <task id="LOCAL-00001" summary="initial commit">
<option name="closed" value="true" /> <option name="closed" value="true" />
@ -176,7 +162,15 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1755963464017</updated> <updated>1755963464017</updated>
</task> </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 /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
@ -184,9 +178,11 @@
</component> </component>
<component name="VcsManagerConfiguration"> <component name="VcsManagerConfiguration">
<MESSAGE value="initial commit" /> <MESSAGE value="initial commit" />
<option name="LAST_COMMIT_MESSAGE" value="initial commit" /> <MESSAGE value="working" />
<option name="LAST_COMMIT_MESSAGE" value="working" />
</component> </component>
<component name="com.intellij.coverage.CoverageDataManagerImpl"> <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$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$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" /> <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" />

78
main.py
View File

@ -1,52 +1,23 @@
import pickle import pickle
import sys import sys
import regex as re
import numpy as np
from ultralytics import YOLO from ultralytics import YOLO
import cv2 import cv2
import time import time
from calculate import normalize_pose, compare_poses_boolean from calculate import normalize_pose, compare_poses_boolean
from draw import draw_new from draw import draw_new
from video_methods import initialize_method
model = YOLO("yolo11x-pose.pt") model = YOLO("yolo11x-pose.pt")
if len(sys.argv) == 1: if len(sys.argv) == 2:
method = sys.argv[1] method_type = sys.argv[1]
else: else:
print("Podaj argument 'cam', albo 'network'.") print("Podaj argument 'cam', albo 'net'.")
exit(1) exit(1)
cap = cv2.VideoCapture(0) method = initialize_method(method_type)
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]]))
do_pose_shot = False do_pose_shot = False
@ -56,6 +27,9 @@ def click_event(event, x, y, flags, param):
if event == cv2.EVENT_LBUTTONDOWN: # lewy przycisk myszy if event == cv2.EVENT_LBUTTONDOWN: # lewy przycisk myszy
do_pose_shot = not do_pose_shot do_pose_shot = not do_pose_shot
def main():
last_time = time.time()
currTimeIndex = 0 currTimeIndex = 0
currIndex = None currIndex = None
currMove = None currMove = None
@ -66,22 +40,6 @@ goodCount = 0
failCount = 0 failCount = 0
failRate = 2 failRate = 2
def wczytaj_dane_z_txt(sciezka):
wynik = []
with open(sciezka, "r") as f:
zawartosc = f.read()
# Znajdź wszystkie krotki w formacie (float, array([...]))
pattern = re.compile(r"\(([^,]+),\s*array\((\[.*?\]),\s*dtype=float32\)\)")
matches = pattern.findall(zawartosc)
for m in matches:
liczba = float(m[0])
tablica = np.array(eval(m[1]), dtype=np.float32)
wynik.append((liczba, tablica))
return wynik
moves = [] moves = []
with open('moves.pkl', 'rb') as f: # 'rb' = read binary with open('moves.pkl', 'rb') as f: # 'rb' = read binary
@ -93,12 +51,9 @@ totalCount = len(moves)
for i, move in enumerate(moves): for i, move in enumerate(moves):
moves[i] = (move[0] - startValue, move[1], move[2]) 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: while True:
ret, frame = cap.read() frame = method.receive_frame()
frame = cv2.flip(frame, 1) frame = cv2.flip(frame, 1)
results = model(frame, verbose=False) 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: if currTimeIndex != 0 and moves.index(find_closest(time.time() - currTimeIndex)) == len(moves) - 1:
mehCount = totalCount - failCount - goodCount 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) exit(1)
if currMove is None: if currMove is None:
@ -193,12 +149,4 @@ while True:
cv2.setMouseCallback('Klatka z kamerki', click_event) cv2.setMouseCallback('Klatka z kamerki', click_event)
cv2.waitKey(1) # Czekaj na naciśnięcie klawisza cv2.waitKey(1) # Czekaj na naciśnięcie klawisza
main()
# 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()

View File

@ -10,6 +10,10 @@ def recvall(sock, n):
data += packet data += packet
return data 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)): def resize_with_padding(image, target_size=(640, 640)):
h, w = image.shape[:2] h, w = image.shape[:2]
target_w, target_h = target_size target_w, target_h = target_size