Update app.py
Browse files
app.py
CHANGED
@@ -280,77 +280,62 @@ def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
|
|
280 |
#Visualize of left leg
|
281 |
cv2.putText(image, str(angleHipL),tuple(np.multiply(angleHipL, [640, 480]).astype(int)),cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 2, cv2.LINE_AA)
|
282 |
|
283 |
-
# Squat logic
|
284 |
-
if 80 < angleKneeL < 110 and 29 < angleHipL < 40:
|
285 |
-
|
286 |
-
else:
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
|
296 |
-
#
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
#
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
#
|
307 |
-
|
308 |
-
#
|
309 |
-
|
310 |
-
#
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
# # 3. Knees not low enough
|
315 |
-
# if 110 < angleKneeL < 130:
|
316 |
-
# print(f"AngleKneeL when Lower Your Hips warning:{angleKneeL}")
|
317 |
-
# cv2.rectangle(image, (220, 40), (450, 80), (0, 0, 0), -1)
|
318 |
-
# cv2.putText(image,f"Lower Your Hips",
|
319 |
-
# (230,60),cv2.FONT_HERSHEY_SIMPLEX,1,(255,255,255),1,cv2.LINE_AA)
|
320 |
|
321 |
|
322 |
-
#
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
#
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
#
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
#
|
343 |
-
#
|
344 |
-
#
|
345 |
-
# print(f"AngleKneeL when valid down position:{angleKneeL}")
|
346 |
-
# print(f"AngleHipL when valid down position:{angleHipL}")
|
347 |
-
# print(f"Correct counter when valid down position:{correct}")
|
348 |
-
# correct+=1
|
349 |
-
# stage='up'
|
350 |
-
# cv2.putText(image,f"Correct:{correct}",
|
351 |
-
# (400,120),cv2.FONT_HERSHEY_SIMPLEX,1,(0,0,0),1,cv2.LINE_AA)
|
352 |
-
# cv2.putText(image,f"Incorrect:{incorrect}",
|
353 |
-
# (400,150),cv2.FONT_HERSHEY_SIMPLEX,1,(0,0,0),1,cv2.LINE_AA)
|
354 |
|
355 |
#Render Counter to our camera screen
|
356 |
#Setup Status box
|
|
|
280 |
#Visualize of left leg
|
281 |
cv2.putText(image, str(angleHipL),tuple(np.multiply(angleHipL, [640, 480]).astype(int)),cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 2, cv2.LINE_AA)
|
282 |
|
283 |
+
# # Squat logic
|
284 |
+
# if 80 < angleKneeL < 110 and 29 < angleHipL < 40:
|
285 |
+
# cv2.putText(image, "Squat Detected!", (300, 100), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 255, 0), 3)
|
286 |
+
# else:
|
287 |
+
# if angleHipL < 29:
|
288 |
+
# cv2.putText(image, "Lean Forward!", (300, 200), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 0, 255), 3)
|
289 |
+
# elif angleHipL > 45:
|
290 |
+
# cv2.putText(image, "Lean Backward!", (300, 200), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 0, 255), 3)
|
291 |
+
# if angleKneeL < 80:
|
292 |
+
# cv2.putText(image, "Squat Too Deep!", (300, 250), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 0, 255), 3)
|
293 |
+
# elif angleKneeL > 110:
|
294 |
+
# cv2.putText(image, "Lower Your Hips!", (300, 300), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 0, 255), 3)
|
295 |
|
296 |
+
# 1. Bend Forward Warning
|
297 |
+
if 10 < angleHipL < 18:
|
298 |
+
cv2.rectangle(image, (310, 180), (450, 220), (0, 0, 0), -1)
|
299 |
+
cv2.putText(image,f"Bend Forward",(320,200),cv2.FONT_HERSHEY_SIMPLEX,1,(150,120,255),1,cv2.LINE_AA)
|
300 |
+
|
301 |
+
# 2. Lean Backward Warning
|
302 |
+
if angleHipL > 45:
|
303 |
+
cv2.rectangle(image, (310, 180), (450, 220), (0, 0, 0), -1)
|
304 |
+
cv2.putText(image,f"Bend Backward",(320,200),cv2.FONT_HERSHEY_SIMPLEX,1,(80,120,255),1,cv2.LINE_AA)
|
305 |
+
|
306 |
+
# stage 2
|
307 |
+
|
308 |
+
# Incorrect movements
|
309 |
+
|
310 |
+
# 3. Knees not low enough
|
311 |
+
if 110 < angleKneeL < 130:
|
312 |
+
cv2.rectangle(image, (220, 40), (450, 80), (0, 0, 0), -1)
|
313 |
+
cv2.putText(image,f"Lower Your Hips",(230,60),cv2.FONT_HERSHEY_SIMPLEX,1,(255,255,255),1,cv2.LINE_AA)
|
|
|
|
|
|
|
|
|
|
|
|
|
314 |
|
315 |
|
316 |
+
# 3. Knees not low enough and not completed the squat
|
317 |
+
if angleKneeL>130 and stage=='mid':
|
318 |
+
cv2.rectangle(image, (220, 40), (450, 80), (0, 0, 0), -1)
|
319 |
+
cv2.putText(image,f"Lower Your Hips",(230,60),cv2.FONT_HERSHEY_SIMPLEX,1,(255,255,255),1,cv2.LINE_AA)
|
320 |
+
incorrect+=1
|
321 |
+
stage='up'
|
322 |
+
|
323 |
+
# 4. Squat too deep
|
324 |
+
if angleKneeL < 80 and stage=='mid':
|
325 |
+
cv2.rectangle(image, (220, 40), (450, 80), (0, 0, 0), -1)
|
326 |
+
cv2.putText(image,f"Squat too deep",(230,60),cv2.FONT_HERSHEY_SIMPLEX,1,(255,255,255),1,cv2.LINE_AA)
|
327 |
+
incorrect +=1
|
328 |
+
stage='up'
|
329 |
+
|
330 |
+
# stage 4
|
331 |
+
if (80 < angleKneeL < 110) and stage=='mid':
|
332 |
+
if (18 < angleHipL < 40): # Valid "down" position
|
333 |
+
correct+=1
|
334 |
+
stage='up'
|
335 |
+
# cv2.putText(image,f"Correct:{correct}",
|
336 |
+
# (400,120),cv2.FONT_HERSHEY_SIMPLEX,1,(0,0,0),1,cv2.LINE_AA)
|
337 |
+
# cv2.putText(image,f"Incorrect:{incorrect}",
|
338 |
+
# (400,150),cv2.FONT_HERSHEY_SIMPLEX,1,(0,0,0),1,cv2.LINE_AA)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
339 |
|
340 |
#Render Counter to our camera screen
|
341 |
#Setup Status box
|