From 017f9d1d8aae8d182dfd35ff91accea4235fc9ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B8=A3=E6=B8=A3=E5=92=8C?= <2608761159@qq.com> Date: Tue, 24 Sep 2024 18:08:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8D=95=E5=8F=8C=E6=9D=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Exercise3/pull_up_1.py | 25 +++++++------ Exercise3/pull_up_2.py | 11 +++--- Exercise3/pull_up_3.py | 11 +++--- Exercise3/tricep_dip.py | 77 +++++++++++++++++++++-------------------- 4 files changed, 68 insertions(+), 56 deletions(-) diff --git a/Exercise3/pull_up_1.py b/Exercise3/pull_up_1.py index 068482b..1bf37c2 100644 --- a/Exercise3/pull_up_1.py +++ b/Exercise3/pull_up_1.py @@ -35,6 +35,7 @@ class PullUp_1(BaseExercise): self.exercise_type = "引体向上" self.end_test = 0 self.had_done = False + self.time_1 = 0 # 摆动状态 self.state = 0 # 初始化 @@ -139,17 +140,19 @@ class PullUp_1(BaseExercise): if self.form == 0: if time.time() - self.sta_time > 1.5: if elbow_1 > 150 and elbow_2 > 150 and shoulder_1 > 100 and shoulder_2 > 100 and eye_1_y > wrist_1_y and eye_2_y > wrist_2_y: - self.form = 1 - self.speak_driver.add_speak("请开始考试") - self.starttime = time.time() - self.initial_wrist_1_y = wrist_1_y - self.initial_wrist_2_y = wrist_2_y - self.initial_height_left = math.sqrt( - math.pow(shoulder_2_x - hip_2_x, 2) + math.pow(shoulder_2_y - hip_2_y, 2)) * math.cos( - math.pi / 6) - self.initial_height_right = math.sqrt( - math.pow(shoulder_1_x - hip_1_x, 2) + math.pow(shoulder_1_y - hip_1_y, 2)) * math.cos( - math.pi / 6) + self.time_1 += 1 + if self.time_1 > 30: + self.form = 1 + self.speak_driver.add_speak("请开始考试") + self.starttime = time.time() + self.initial_wrist_1_y = wrist_1_y + self.initial_wrist_2_y = wrist_2_y + self.initial_height_left = math.sqrt( + math.pow(shoulder_2_x - hip_2_x, 2) + math.pow(shoulder_2_y - hip_2_y, 2)) * math.cos( + math.pi / 4) + self.initial_height_right = math.sqrt( + math.pow(shoulder_1_x - hip_1_x, 2) + math.pow(shoulder_1_y - hip_1_y, 2)) * math.cos( + math.pi / 4) elif self.pre_pos == 1 and self.form == 1: height_left = math.sqrt(math.pow(shoulder_2_x - hip_2_x, 2) + math.pow(shoulder_2_y - hip_2_y, 2)) diff --git a/Exercise3/pull_up_2.py b/Exercise3/pull_up_2.py index 4760bce..d93f211 100644 --- a/Exercise3/pull_up_2.py +++ b/Exercise3/pull_up_2.py @@ -32,6 +32,7 @@ class PullUp_2(BaseExercise): self.exercise_type = "引体向上" self.end_test = 0 self.had_done = False + self.time_1 = 0 # 摆动状态 self.state = 0 # 初始化 @@ -123,10 +124,12 @@ class PullUp_2(BaseExercise): if self.form == 0: if time.time() - self.sta_time > 1.5: if elbow_1 > 150 and elbow_2 > 150 and shoulder_1 > 100 and shoulder_2 > 100 and eye_1_y > wrist_1_y and eye_2_y > wrist_2_y: - self.form = 1 - self.speak_driver.add_speak("请开始考试") - self.starttime = time.time() - self.initial_wrist_y = wrist_1_y + self.time_1 += 1 + if self.time_1 > 20: + self.form = 1 + self.speak_driver.add_speak("请开始考试") + self.starttime = time.time() + self.initial_wrist_y = wrist_1_y elif self.pre_pos == 1 and self.form == 1: hand_1_y = (wrist_1_y + index_1_y) / 2 diff --git a/Exercise3/pull_up_3.py b/Exercise3/pull_up_3.py index 45c18c6..302a213 100644 --- a/Exercise3/pull_up_3.py +++ b/Exercise3/pull_up_3.py @@ -26,6 +26,7 @@ class PullUp_3(BaseExercise): # 开始标志 self.form = 0 # 状态反馈 + self.time_1 = 0 self.pre_pos = 0 self.sta_time = time.time() self.feedback = "开始" @@ -123,10 +124,12 @@ class PullUp_3(BaseExercise): if self.form == 0: if time.time() - self.sta_time > 1.5: if elbow_1 > 150 and elbow_2 > 150 and shoulder_1 > 100 and shoulder_2 > 100 and eye_1_y > wrist_1_y and eye_2_y > wrist_2_y: - self.form = 1 - self.speak_driver.add_speak("请开始考试") - self.starttime = time.time() - self.initial_wrist_y = wrist_1_y + self.time_1 += 1 + if self.time_1 > 20: + self.form = 1 + self.speak_driver.add_speak("请开始考试") + self.starttime = time.time() + self.initial_wrist_y = wrist_1_y elif self.pre_pos == 1 and self.form == 1: hand_1_y = (wrist_1_y + index_1_y) / 2 diff --git a/Exercise3/tricep_dip.py b/Exercise3/tricep_dip.py index f8850ec..54cdf01 100644 --- a/Exercise3/tricep_dip.py +++ b/Exercise3/tricep_dip.py @@ -1,6 +1,3 @@ -import math -import time - import numpy as np from MCamera.mp_camera import * @@ -20,6 +17,7 @@ class Tricep_dip_1(BaseExercise): # 当前状态 self.heel = 0 # 动作持续帧数 + self.time_0 = 0 self.time_2 = 0 self.time_1 = 0 self.time = 0 @@ -42,7 +40,7 @@ class Tricep_dip_1(BaseExercise): self.initial_wrist_2_y = 0 # 双杠臂屈伸参数 - self.corner = (0, 480, 260, 380) + self.corner = (0, 480, 230, 410) MediapipeAlgorithmPlugin.set_corner(corner=self.corner) MediapipeAlgorithmPlugin.set_config(config=self.config) @@ -108,19 +106,23 @@ class Tricep_dip_1(BaseExercise): if len(lm_list) != 0: elbow_1 = self.detector.findAngle(img, 11, 13, 15) elbow_2 = self.detector.findAngle(img, 12, 14, 16) + shoulder_1 = self.detector.findAngle(img, 13, 11, 23) + shoulder_2 = self.detector.findAngle(img, 14, 12, 24) eye_1_y = self.detector.findPosition(img, False)[3][2] eye_2_y = self.detector.findPosition(img, False)[6][2] elbow_1_x = self.detector.findPosition(img, False)[13][1] elbow_1_y = self.detector.findPosition(img, False)[13][2] elbow_2_x = self.detector.findPosition(img, False)[14][1] elbow_2_y = self.detector.findPosition(img, False)[14][2] + wrist_1_x = self.detector.findPosition(img, False)[15][1] + wrist_2_x = self.detector.findPosition(img, False)[16][1] wrist_1_y = self.detector.findPosition(img, False)[15][2] wrist_2_y = self.detector.findPosition(img, False)[16][2] heel_y = self.detector.findPosition(img, False)[27][2] shoulder_1_x = self.detector.findPosition(img, False)[11][1] - shoulder_2_x = self.detector.findPosition(img, False)[11][1] + shoulder_2_x = self.detector.findPosition(img, False)[12][1] shoulder_1_y = self.detector.findPosition(img, False)[11][2] - shoulder_2_y = self.detector.findPosition(img, False)[11][2] + shoulder_2_y = self.detector.findPosition(img, False)[12][2] vis_shoulder_1 = self.detector.findPosition(img, False)[11][4] vis_shoulder_2 = self.detector.findPosition(img, False)[12][4] @@ -132,40 +134,41 @@ class Tricep_dip_1(BaseExercise): self.speak_driver.add_speak("双手握杠后,进入准备状态") self.pre_pos = 1 - if self.form == 0 and self.pre_pos == 1: if self.readiness_state == 0: - if elbow_1 < 90 and elbow_2 < 90: + if shoulder_1 > 70 and shoulder_2 > 70: self.readiness_state = 1 - # self.heel = heel_y + self.heel = heel_y self.speak_driver.add_speak("上杠,听到提示声后开始考试") if self.readiness_state == 1: - # if elbow_1 > 157 and eye_1_y < wrist_1_y and eye_2_y < wrist_2_y and heel_y < self.heel - 50: - if elbow_1 > 157 and elbow_2 > 157 and eye_1_y < wrist_1_y and eye_2_y < wrist_2_y: - if vis_shoulder_1 > 0.8 and vis_shoulder_1 > vis_shoulder_2: - self.time_1 += 1 - if self.time_1 > 3: - self.dir = 1 - self.sign = 1 - self.time_1 = 0 - self.time_2 = 0 - elif vis_shoulder_2 > 0.8 and vis_shoulder_1 < vis_shoulder_2: - self.time_2 += 1 - if self.time_2 > 3: - self.dir = 2 - self.sign = 1 - self.time_2 = 0 - self.time_1 = 0 - if self.sign == 1: - self.form = 1 - beep() - self.starttime = time.time() - self.initial_wrist_1_y = wrist_1_y - self.initial_wrist_2_y = wrist_2_y + if elbow_1 > 157 and eye_1_y < wrist_1_y and eye_2_y < wrist_2_y and (shoulder_1 < 30 or shoulder_2 < 30) and heel_y < self.heel - 50: + # if elbow_1 > 157 and eye_1_y < wrist_1_y and eye_2_y < wrist_2_y and (shoulder_1 < 30 or shoulder_2 < 30): + self.time_0 += 1 + if self.time_0 > 30: + if vis_shoulder_1 > 0.8 and vis_shoulder_1 > vis_shoulder_2: + self.time_1 += 1 + if self.time_1 > 3: + self.dir = 1 + self.sign = 1 + self.time_1 = 0 + self.time_2 = 0 + elif vis_shoulder_2 > 0.8 and vis_shoulder_1 < vis_shoulder_2: + self.time_2 += 1 + if self.time_2 > 3: + self.dir = 2 + self.sign = 1 + self.time_2 = 0 + self.time_1 = 0 + if self.sign == 1: + self.form = 1 + beep() + self.starttime = time.time() + self.initial_wrist_1_y = wrist_1_y + self.initial_wrist_2_y = wrist_2_y if self.dir == 1 and self.pre_pos == 1 and self.form == 1: - # if wrist_1_y - self.initial_wrist_1_y > 50 or heel_y < self.heel - 10: - if wrist_1_y - self.initial_wrist_1_y > 50: + shoulder_angle = self.detector.findIncludedAngle(elbow_1_x, elbow_1_y, wrist_1_x, wrist_1_x) + if wrist_2_y - self.initial_wrist_2_y > 50 or wrist_1_y - self.initial_wrist_1_y > 50 or heel_y < self.heel - 5: self.end_test += 1 if self.end_test > 2: self.speak_driver.add_speak("双手已离开双杠,考试结束") @@ -181,7 +184,7 @@ class Tricep_dip_1(BaseExercise): self.state = 0 self.time = 0 - if elbow_1 >= 157 and shoulder_1_y < elbow_1_y and not self.had_done and self.count > 0: + if elbow_1 >= 160 and shoulder_1_y < elbow_1_y and shoulder_1_y < self.initial_wrist_1_y - 60 and shoulder_angle > 60 and not self.had_done and self.count > 0: self.feedback = "下落" if self.state == 0: self.time += 1 @@ -193,7 +196,8 @@ class Tricep_dip_1(BaseExercise): self.initial_wrist_1_y = wrist_1_y self.initial_wrist_2_y = wrist_2_y elif self.dir == 2 and self.pre_pos == 1 and self.form == 1: - if wrist_2_y - self.initial_wrist_2_y > 50: + shoulder_angle = self.detector.findIncludedAngle(elbow_2_x, elbow_2_y, wrist_2_x, wrist_2_x) + if wrist_2_y - self.initial_wrist_2_y > 50 or wrist_1_y - self.initial_wrist_1_y > 50 or heel_y < self.heel - 5: self.end_test += 1 if self.end_test > 2: self.speak_driver.add_speak("双手已离开双杠,考试结束") @@ -209,7 +213,7 @@ class Tricep_dip_1(BaseExercise): self.state = 0 self.time = 0 - if elbow_2 >= 157 and shoulder_2_y < elbow_2_y and not self.had_done and self.count > 0: + if elbow_2 >= 160 and shoulder_2_y < elbow_2_y and shoulder_2_y < self.initial_wrist_2_y - 60 and shoulder_angle > 60 and not self.had_done and self.count > 0: self.feedback = "下落" if self.state == 0: self.time += 1 @@ -220,4 +224,3 @@ class Tricep_dip_1(BaseExercise): if self.count == 1: self.initial_wrist_1_y = wrist_1_y self.initial_wrist_2_y = wrist_2_y -