Pratyush101 commited on
Commit
ab370b0
·
verified ·
1 Parent(s): 3960910

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -68
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
- 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
- # print(f"AngleHipL when Bend forward warning:{angleHipL}")
299
- # cv2.rectangle(image, (310, 180), (450, 220), (0, 0, 0), -1)
300
- # cv2.putText(image,f"Bend Forward",
301
- # (320,200),cv2.FONT_HERSHEY_SIMPLEX,1,(150,120,255),1,cv2.LINE_AA)
302
-
303
- # # 2. Lean Backward Warning
304
- # if angleHipL > 45:
305
- # print(f"AngleHipL when Bend backward warning:{angleHipL}")
306
- # cv2.rectangle(image, (310, 180), (450, 220), (0, 0, 0), -1)
307
- # cv2.putText(image,f"Bend Backward",
308
- # (320,200),cv2.FONT_HERSHEY_SIMPLEX,1,(80,120,255),1,cv2.LINE_AA)
309
-
310
- # stage 2
311
-
312
- # Incorrect movements
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
- # # 3. Knees not low enough and not completed the squat
323
- # if angleKneeL>130 and stage=='mid':
324
- # print(f"AngleKneeL when Knees not low enough and not completed the squat :{angleKneeL}")
325
- # cv2.rectangle(image, (220, 40), (450, 80), (0, 0, 0), -1)
326
- # cv2.putText(image,f"Lower Your Hips",
327
- # (230,60),cv2.FONT_HERSHEY_SIMPLEX,1,(255,255,255),1,cv2.LINE_AA)
328
- # print(f"Incorrect counter Knees not low enough and not completed the squat :{incorrect}")
329
- # incorrect+=1
330
- # stage='up'
331
-
332
- # # 4. Squat too deep
333
- # if angleKneeL < 80 and stage=='mid':
334
- # print(f"AngleKneeL when Squat too deep warning:{angleKneeL}")
335
- # cv2.rectangle(image, (220, 40), (450, 80), (0, 0, 0), -1)
336
- # cv2.putText(image,f"Squat too deep",
337
- # (230,60),cv2.FONT_HERSHEY_SIMPLEX,1,(255,255,255),1,cv2.LINE_AA)
338
- # print(f"Incorrect counter when Squat too deep warning:{incorrect}")
339
- # incorrect +=1
340
- # stage='up'
341
-
342
- # # stage 4
343
- # if (80 < angleKneeL < 110) and stage=='mid':
344
- # if (18 < angleHipL < 40): # Valid "down" position
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