Commit ·
5c09023
1
Parent(s): 8963f04
fix beep detection retry
Browse files
app.py
CHANGED
|
@@ -98,10 +98,22 @@ def detect_beeps(video_path, event_length=30):
|
|
| 98 |
# top_q = np.max(corr) - 0.1
|
| 99 |
# mean = np.mean(corr)
|
| 100 |
# print(top_q, mean)
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
# plt.plot(corr)
|
| 106 |
# plt.plot(peaks, corr[peaks], "x")
|
| 107 |
# plt.savefig('beep.png')
|
|
@@ -123,10 +135,11 @@ def inference(stream_url, start_time, end_time, beep_detection_on, event_length,
|
|
| 123 |
has_access = pbkdf2_sha256.verify(os.environ['DEV_API_TOKEN'], api_key)
|
| 124 |
if not has_access:
|
| 125 |
return "Invalid API Key"
|
|
|
|
| 126 |
if beep_detection_on:
|
| 127 |
event_start, event_end = detect_beeps(in_video, event_length)
|
| 128 |
print(event_start, event_end)
|
| 129 |
-
|
| 130 |
cap = cv2.VideoCapture(in_video)
|
| 131 |
length = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
|
| 132 |
frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
|
|
|
| 98 |
# top_q = np.max(corr) - 0.1
|
| 99 |
# mean = np.mean(corr)
|
| 100 |
# print(top_q, mean)
|
| 101 |
+
beep_height = 0.8
|
| 102 |
+
event_start = length
|
| 103 |
+
while length - event_start < fps * event_length:
|
| 104 |
+
peaks, _ = find_peaks(corr, height=beep_height, distance=fs)
|
| 105 |
+
event_start = int(peaks[0] / fs * fps)
|
| 106 |
+
event_end = int(peaks[-1] / fs * fps)
|
| 107 |
+
if event_end == event_start:
|
| 108 |
+
event_end = event_start + fps * event_length
|
| 109 |
+
beep_height -= 0.1
|
| 110 |
+
if beep_height <= 0.1:
|
| 111 |
+
event_start = 0
|
| 112 |
+
event_end = length
|
| 113 |
+
break
|
| 114 |
+
#peaks, _ = find_peaks(corr, height=0.7, distance=fs)
|
| 115 |
+
#event_start = int(peaks[0] / fs * fps)
|
| 116 |
+
#event_end = int(peaks[-1] / fs * fps)
|
| 117 |
# plt.plot(corr)
|
| 118 |
# plt.plot(peaks, corr[peaks], "x")
|
| 119 |
# plt.savefig('beep.png')
|
|
|
|
| 135 |
has_access = pbkdf2_sha256.verify(os.environ['DEV_API_TOKEN'], api_key)
|
| 136 |
if not has_access:
|
| 137 |
return "Invalid API Key"
|
| 138 |
+
event_length = int(event_length)
|
| 139 |
if beep_detection_on:
|
| 140 |
event_start, event_end = detect_beeps(in_video, event_length)
|
| 141 |
print(event_start, event_end)
|
| 142 |
+
|
| 143 |
cap = cv2.VideoCapture(in_video)
|
| 144 |
length = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
|
| 145 |
frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|