forked from MVIG-SJTU/AlphaPose
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpull_up.py
More file actions
56 lines (45 loc) · 1.72 KB
/
Copy pathpull_up.py
File metadata and controls
56 lines (45 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import json
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import find_peaks
keyword = ["Nose", "LEye", "REye", "LEar", "REar", "LShoulder", "RShoulder", "LElbow", "RElbow", "LWrist", "RWrist",
"LHip", "RHip", "LKnee", "Rknee", "LAnkle", "RAnkle"]
def find_apex(y_):
y_min = min(y_)
y_max = max(y_)
distance = None # 相邻峰值之间的最小水平距离,越小去噪越严格
height_base = y_min + (y_max - y_min) * 0.1 # 峰值的最小高度
prominence = (y_max - height_base) * 0.1 # 相邻两个波峰的最小突起程度
peaks, properties = find_peaks(y_, height=height_base, distance=distance, prominence=prominence)
return peaks
def get_gravity(a, b, c):
"""
直角坐标系计算三角形重心
:param 三个点的坐标
:return: [x,y]
"""
x_ = (a[0] + b[0] + c[0]) / 3
y_ = (a[1] + b[1] + c[1]) / 3
gravity = [x_, y_]
return gravity
def pullup_count(data_path):
with open(data_path, 'r') as load_f:
data_dict = json.load(load_f)
gravities = []
for item in range(len(data_dict)):
Nose = data_dict[item]['keypoints'][0:2]
LShoulder = data_dict[item]['keypoints'][15:17]
RShoulder = data_dict[item]['keypoints'][18:20]
gravity = get_gravity(Nose, LShoulder, RShoulder)
gravities.append(gravity)
x_ = np.arange(0, len(gravities), 1)
y_ = np.array((gravities))[:, 1]
peaks = find_apex(y_)
count = len(peaks)
plt.plot(x_, y_)
plt.plot(peaks, y_[peaks], color='red')
plt.show()
print('count: ', count)
return count
# json_path = 'lenovo/pull_up_10.json'
# count = get_count(json_path)