Skip to content

Commit 7a96e67

Browse files
committed
Part of the way to a solution
1 parent 29f3731 commit 7a96e67

File tree

2 files changed

+32
-44
lines changed

2 files changed

+32
-44
lines changed

bin/hud.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ def main():
2828
type=str,
2929
help="Override the default face/neck keypoints (default=%(default)s)",
3030
)
31-
parser.add_argument(
32-
"--minimum-bop-spacing",
33-
type=float,
34-
default=0.2,
35-
help="Minimum spacing (in seconds) between bops to filter out implausible events (default=%(default)s)",
36-
)
3731
parser.add_argument(
3832
"--bpm-frame-history",
3933
type=float,
@@ -152,8 +146,9 @@ def process_first_pass(*args, **kwargs):
152146
# get head bop locations by indexing into time array
153147
all_time = numpy.linspace(0, frame_duration * total_frames, int(total_frames))
154148

155-
peaks, strongest_peaks_index = pose_tracker.find_peaks()
156-
bop_locations = all_time[peaks[strongest_peaks_index]]
149+
# take top peaks only
150+
peaks = pose_tracker.find_peaks()[0][1]
151+
bop_locations = all_time[peaks]
157152

158153
event_thresh = args.event_threshold_frames * frame_duration
159154

@@ -191,7 +186,6 @@ def process_second_pass(get_frame_fn, frame_time):
191186
bop_history = bop_locations[
192187
numpy.where((bop_locations >= frame_min) & (bop_locations <= frame_max))
193188
]
194-
bop_history = bops_realistic_smoothing(bop_history, args.minimum_bop_spacing)
195189

196190
all_beats_bpm_tmp = bpm_from_beats(all_beat_history)
197191
bop_bpm_tmp = bpm_from_beats(bop_history)

headbang/motion.py

+29-35
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import numpy
22
import sys
3-
import itertools
43
import os
54
import scipy
65
from scipy.signal import find_peaks, find_peaks_cwt, peak_prominences
@@ -14,14 +13,13 @@
1413

1514
import pyopenpose as op
1615

17-
marker = itertools.cycle((",", "+", ".", "o", "*"))
18-
1916

2017
class OpenposeDetector:
21-
# nose, neck, right eye, left eye, right ear, left ear
22-
face_neck_keypoints = [0, 1, 15, 16, 17, 18]
18+
# nose, right eye, left eye, right ear, left ear
19+
face_neck_keypoints = [0, 15, 16, 17, 18]
2320
confidence_threshold = 0.5
24-
peak_prominence = 0.2
21+
peak_prominence = 0.05
22+
obj_limit = 2
2523

2624
def __init__(self, n_frames, custom_keypoints=None):
2725
config = {}
@@ -100,56 +98,52 @@ def process_frame(self, frame):
10098

10199
def find_peaks(self):
102100
peaks = [
103-
find_peaks(
104-
numpy.nan_to_num(y_coords), prominence=OpenposeDetector.peak_prominence
105-
)
101+
find_peaks(y_coords, prominence=OpenposeDetector.peak_prominence)
106102
for y_coords in self.all_y_coords
107103
]
108104
peaks = [p[0] for p in peaks]
109105

110106
prominences = [
111-
peak_prominences(numpy.nan_to_num(y_coords), peaks[i])
107+
peak_prominences(y_coords, peaks[i])
112108
for i, y_coords in enumerate(self.all_y_coords)
113109
]
114110
prominences = [p[1] for p in prominences]
115111

116-
strongest_peaks_index = prominences.index(max(prominences, key=sum))
112+
top_ycoords_and_peaks = [
113+
(ycrds, pks)
114+
for _, pks, ycrds in sorted(
115+
zip(prominences, peaks, self.all_y_coords),
116+
key=lambda triplet: sum(triplet[0]),
117+
reverse=True,
118+
)
119+
]
117120

118-
return peaks, strongest_peaks_index
121+
# only track up to obj_limit objects
122+
return top_ycoords_and_peaks[: OpenposeDetector.obj_limit]
119123

120124
def plot_ycoords(self):
121-
peaks, strongest_peaks_index = self.find_peaks()
122-
123125
plt.figure(1)
124126
plt.title("normalized y coordinate motion")
125127

126128
plt.xlabel("frame")
127129
plt.ylabel("y coord")
128130

129131
frames = numpy.arange(self.n_frames)
132+
best_coords_and_peaks = self.find_peaks()
130133

131-
for i, y_coords in enumerate(self.all_y_coords):
134+
for i, coordspeaks in enumerate(best_coords_and_peaks):
135+
y_coords, peaks = coordspeaks
132136
y_coords = numpy.asarray(y_coords)
133-
plt.plot(frames, y_coords, label="obj {0}".format(i))
134-
135-
if i == strongest_peaks_index:
136-
# mark the strongest peaks in a thicker manner
137-
plt.plot(
138-
peaks[i],
139-
y_coords[peaks[i]],
140-
marker=next(marker),
141-
linestyle="None",
142-
markersize=8,
143-
color="black",
144-
)
145-
else:
146-
plt.plot(
147-
peaks[i],
148-
y_coords[peaks[i]],
149-
marker=next(marker),
150-
linestyle="None",
151-
markersize=5,
152-
)
137+
plt.plot(
138+
frames,
139+
y_coords,
140+
"-D",
141+
label="obj {0}".format(i),
142+
markevery=peaks,
143+
mec="black",
144+
mfc="black",
145+
)
146+
153147
plt.legend()
154148
plt.show()
155149

0 commit comments

Comments
 (0)