Kunal7 commited on
Commit
3757953
1 Parent(s): c01f525

Update process_frame.py

Browse files
Files changed (1) hide show
  1. process_frame.py +63 -45
process_frame.py CHANGED
@@ -22,7 +22,7 @@ class ProcessFrame:
22
  # set radius to draw arc
23
  self.radius = 20
24
 
25
- # Colors in BGR format.
26
  self.COLORS = {
27
  'blue' : (0, 127, 255),
28
  'red' : (255, 50, 50),
@@ -140,6 +140,7 @@ class ProcessFrame:
140
  pos=(30, 80),
141
  text_color=(0, 0, 0),
142
  font_scale=0.6,
 
143
  text_color_bg=(255, 255, 0)
144
  )
145
 
@@ -150,6 +151,7 @@ class ProcessFrame:
150
  pos=(30, dict_maps[idx][1]),
151
  text_color=(255, 255, 230),
152
  font_scale=0.6,
 
153
  text_color_bg=dict_maps[idx][2]
154
  )
155
 
@@ -198,39 +200,43 @@ class ProcessFrame:
198
  frame = cv2.flip(frame, 1)
199
 
200
  if display_inactivity:
201
- # cv2.putText(frame, 'Resetting SQUAT_COUNT due to inactivity!!!', (10, frame_height - 90),
202
- # self.font, 0.5, self.COLORS['blue'], 2, lineType=self.linetype)
203
  play_sound = 'reset_counters'
204
  self.state_tracker['INACTIVE_TIME_FRONT'] = 0.0
205
  self.state_tracker['start_inactive_time_front'] = time.perf_counter()
206
 
207
  draw_text(
208
  frame,
209
- "CORRECT: " + str(self.state_tracker['SQUAT_COUNT']),
210
- pos=(int(frame_width*0.68), 30),
211
  text_color=(255, 255, 230),
212
- font_scale=0.7,
213
- text_color_bg=(18, 185, 0)
 
 
 
214
  )
215
 
216
 
217
  draw_text(
218
  frame,
219
- "INCORRECT: " + str(self.state_tracker['IMPROPER_SQUAT']),
220
- pos=(int(frame_width*0.68), 80),
221
  text_color=(255, 255, 230),
222
- font_scale=0.7,
223
  text_color_bg=(221, 0, 0),
224
-
 
 
225
  )
226
 
227
 
228
  draw_text(
229
  frame,
230
- 'CAMERA NOT ALIGNED PROPERLY!!!',
231
  pos=(30, frame_height-60),
232
  text_color=(255, 255, 230),
233
- font_scale=0.65,
 
234
  text_color_bg=(255, 153, 0),
235
  )
236
 
@@ -240,7 +246,8 @@ class ProcessFrame:
240
  'OFFSET ANGLE: '+str(offset_angle),
241
  pos=(30, frame_height-30),
242
  text_color=(255, 255, 230),
243
- font_scale=0.65,
 
244
  text_color_bg=(255, 153, 0),
245
  )
246
 
@@ -324,12 +331,12 @@ class ProcessFrame:
324
 
325
 
326
  # Join landmarks.
327
- cv2.line(frame, shldr_coord, elbow_coord, self.COLORS['light_blue'], 4, lineType=self.linetype)
328
- cv2.line(frame, wrist_coord, elbow_coord, self.COLORS['light_blue'], 4, lineType=self.linetype)
329
- cv2.line(frame, shldr_coord, hip_coord, self.COLORS['light_blue'], 4, lineType=self.linetype)
330
- cv2.line(frame, knee_coord, hip_coord, self.COLORS['light_blue'], 4, lineType=self.linetype)
331
- cv2.line(frame, ankle_coord, knee_coord,self.COLORS['light_blue'], 4, lineType=self.linetype)
332
- cv2.line(frame, ankle_coord, foot_coord, self.COLORS['light_blue'], 4, lineType=self.linetype)
333
 
334
  # Plot landmark points
335
  cv2.circle(frame, shldr_coord, 7, self.COLORS['yellow'], -1, lineType=self.linetype)
@@ -454,35 +461,40 @@ class ProcessFrame:
454
 
455
 
456
  if display_inactivity:
457
- # cv2.putText(frame, 'Resetting COUNTERS due to inactivity!!!', (10, frame_height - 20), self.font, 0.5, self.COLORS['blue'], 2, lineType=self.linetype)
458
  play_sound = 'reset_counters'
459
  self.state_tracker['start_inactive_time'] = time.perf_counter()
460
  self.state_tracker['INACTIVE_TIME'] = 0.0
461
 
462
 
463
- cv2.putText(frame, str(int(hip_vertical_angle)), (hip_text_coord_x, hip_coord[1]), self.font, 0.6, self.COLORS['light_green'], 2, lineType=self.linetype)
464
- cv2.putText(frame, str(int(knee_vertical_angle)), (knee_text_coord_x, knee_coord[1]+10), self.font, 0.6, self.COLORS['light_green'], 2, lineType=self.linetype)
465
- cv2.putText(frame, str(int(ankle_vertical_angle)), (ankle_text_coord_x, ankle_coord[1]), self.font, 0.6, self.COLORS['light_green'], 2, lineType=self.linetype)
466
 
467
 
468
  draw_text(
469
  frame,
470
- "CORRECT: " + str(self.state_tracker['SQUAT_COUNT']),
471
- pos=(int(frame_width*0.68), 30),
472
  text_color=(255, 255, 230),
473
- font_scale=0.7,
474
- text_color_bg=(18, 185, 0)
 
 
 
475
  )
476
 
477
 
478
  draw_text(
479
  frame,
480
- "INCORRECT: " + str(self.state_tracker['IMPROPER_SQUAT']),
481
- pos=(int(frame_width*0.68), 80),
482
  text_color=(255, 255, 230),
483
- font_scale=0.7,
484
  text_color_bg=(221, 0, 0),
485
-
 
 
486
  )
487
 
488
 
@@ -506,30 +518,36 @@ class ProcessFrame:
506
  if self.state_tracker['INACTIVE_TIME'] >= self.thresholds['INACTIVE_THRESH']:
507
  self.state_tracker['SQUAT_COUNT'] = 0
508
  self.state_tracker['IMPROPER_SQUAT'] = 0
509
- # cv2.putText(frame, 'Resetting SQUAT_COUNT due to inactivity!!!', (10, frame_height - 25), self.font, 0.7, self.COLORS['blue'], 2)
510
  display_inactivity = True
511
 
512
  self.state_tracker['start_inactive_time'] = end_time
513
 
514
  draw_text(
515
  frame,
516
- "CORRECT: " + str(self.state_tracker['SQUAT_COUNT']),
517
- pos=(int(frame_width*0.68), 30),
518
  text_color=(255, 255, 230),
519
- font_scale=0.7,
520
- text_color_bg=(18, 185, 0)
 
 
 
521
  )
522
 
523
 
524
  draw_text(
525
- frame,
526
- "INCORRECT: " + str(self.state_tracker['IMPROPER_SQUAT']),
527
- pos=(int(frame_width*0.68), 80),
528
- text_color=(255, 255, 230),
529
- font_scale=0.7,
530
- text_color_bg=(221, 0, 0),
531
-
532
- )
 
 
 
533
 
534
  if display_inactivity:
535
  play_sound = 'reset_counters'
 
22
  # set radius to draw arc
23
  self.radius = 20
24
 
25
+ # Colors in RGB format.
26
  self.COLORS = {
27
  'blue' : (0, 127, 255),
28
  'red' : (255, 50, 50),
 
140
  pos=(30, 80),
141
  text_color=(0, 0, 0),
142
  font_scale=0.6,
143
+ font_thickness=2,
144
  text_color_bg=(255, 255, 0)
145
  )
146
 
 
151
  pos=(30, dict_maps[idx][1]),
152
  text_color=(255, 255, 230),
153
  font_scale=0.6,
154
+ font_thickness=2,
155
  text_color_bg=dict_maps[idx][2]
156
  )
157
 
 
200
  frame = cv2.flip(frame, 1)
201
 
202
  if display_inactivity:
 
 
203
  play_sound = 'reset_counters'
204
  self.state_tracker['INACTIVE_TIME_FRONT'] = 0.0
205
  self.state_tracker['start_inactive_time_front'] = time.perf_counter()
206
 
207
  draw_text(
208
  frame,
209
+ 'CORRECT: '+str(self.state_tracker['SQUAT_COUNT']),
210
+ pos=(int(frame_width*0.70), 30),
211
  text_color=(255, 255, 230),
212
+ font_scale=0.6,
213
+ text_color_bg=(18, 185, 0),
214
+ font_thickness=2,
215
+ overlay_image=True,
216
+ overlay_type='correct'
217
  )
218
 
219
 
220
  draw_text(
221
  frame,
222
+ 'INCORRECT: '+str(self.state_tracker['IMPROPER_SQUAT']),
223
+ pos=(int(frame_width*0.70), 100),
224
  text_color=(255, 255, 230),
225
+ font_scale=0.6,
226
  text_color_bg=(221, 0, 0),
227
+ font_thickness=2,
228
+ overlay_image=True,
229
+ overlay_type='incorrect'
230
  )
231
 
232
 
233
  draw_text(
234
  frame,
235
+ 'CAMERA NOT ALIGNED PROPERLY',
236
  pos=(30, frame_height-60),
237
  text_color=(255, 255, 230),
238
+ font_scale=0.6,
239
+ font_thickness=2,
240
  text_color_bg=(255, 153, 0),
241
  )
242
 
 
246
  'OFFSET ANGLE: '+str(offset_angle),
247
  pos=(30, frame_height-30),
248
  text_color=(255, 255, 230),
249
+ font_scale=0.6,
250
+ font_thickness=2,
251
  text_color_bg=(255, 153, 0),
252
  )
253
 
 
331
 
332
 
333
  # Join landmarks.
334
+ cv2.line(frame, shldr_coord, elbow_coord, self.COLORS['light_blue'], 5, lineType=self.linetype)
335
+ cv2.line(frame, wrist_coord, elbow_coord, self.COLORS['light_blue'], 5, lineType=self.linetype)
336
+ cv2.line(frame, shldr_coord, hip_coord, self.COLORS['light_blue'], 5, lineType=self.linetype)
337
+ cv2.line(frame, knee_coord, hip_coord, self.COLORS['light_blue'], 5, lineType=self.linetype)
338
+ cv2.line(frame, ankle_coord, knee_coord,self.COLORS['light_blue'], 5, lineType=self.linetype)
339
+ cv2.line(frame, ankle_coord, foot_coord, self.COLORS['light_blue'], 5, lineType=self.linetype)
340
 
341
  # Plot landmark points
342
  cv2.circle(frame, shldr_coord, 7, self.COLORS['yellow'], -1, lineType=self.linetype)
 
461
 
462
 
463
  if display_inactivity:
464
+
465
  play_sound = 'reset_counters'
466
  self.state_tracker['start_inactive_time'] = time.perf_counter()
467
  self.state_tracker['INACTIVE_TIME'] = 0.0
468
 
469
 
470
+ cv2.putText(frame, str(int(hip_vertical_angle)), (hip_text_coord_x, hip_coord[1]), self.font, 0.8, (187, 51, 255), 2, lineType=self.linetype)
471
+ cv2.putText(frame, str(int(knee_vertical_angle)), (knee_text_coord_x, knee_coord[1]+10), self.font, 0.8, (187, 51, 255), 2, lineType=self.linetype)
472
+ cv2.putText(frame, str(int(ankle_vertical_angle)), (ankle_text_coord_x, ankle_coord[1]), self.font, 0.8, (187, 51, 255), 2, lineType=self.linetype)
473
 
474
 
475
  draw_text(
476
  frame,
477
+ 'CORRECT: '+str(self.state_tracker['SQUAT_COUNT']),
478
+ pos=(int(frame_width*0.70), 30),
479
  text_color=(255, 255, 230),
480
+ font_scale=0.6,
481
+ text_color_bg=(18, 185, 0),
482
+ font_thickness=2,
483
+ overlay_image=True,
484
+ overlay_type='correct'
485
  )
486
 
487
 
488
  draw_text(
489
  frame,
490
+ 'INCORRECT: '+str(self.state_tracker['IMPROPER_SQUAT']),
491
+ pos=(int(frame_width*0.70), 100),
492
  text_color=(255, 255, 230),
493
+ font_scale=0.6,
494
  text_color_bg=(221, 0, 0),
495
+ font_thickness=2,
496
+ overlay_image=True,
497
+ overlay_type='incorrect'
498
  )
499
 
500
 
 
518
  if self.state_tracker['INACTIVE_TIME'] >= self.thresholds['INACTIVE_THRESH']:
519
  self.state_tracker['SQUAT_COUNT'] = 0
520
  self.state_tracker['IMPROPER_SQUAT'] = 0
521
+
522
  display_inactivity = True
523
 
524
  self.state_tracker['start_inactive_time'] = end_time
525
 
526
  draw_text(
527
  frame,
528
+ 'CORRECT: '+str(self.state_tracker['SQUAT_COUNT']),
529
+ pos=(int(frame_width*0.70), 30),
530
  text_color=(255, 255, 230),
531
+ font_scale=0.6,
532
+ text_color_bg=(18, 185, 0),
533
+ font_thickness=2,
534
+ overlay_image=True,
535
+ overlay_type='correct'
536
  )
537
 
538
 
539
  draw_text(
540
+ frame,
541
+ 'INCORRECT: '+str(self.state_tracker['IMPROPER_SQUAT']),
542
+ pos=(int(frame_width*0.70), 100),
543
+ text_color=(255, 255, 230),
544
+ font_scale=0.6,
545
+ text_color_bg=(221, 0, 0),
546
+ font_thickness=2,
547
+ overlay_image=True,
548
+ overlay_type='incorrect'
549
+ )
550
+
551
 
552
  if display_inactivity:
553
  play_sound = 'reset_counters'