HEMANTH commited on
Commit
591ff49
·
1 Parent(s): f17c448

changed the code to access camera

Browse files
Files changed (2) hide show
  1. app.py +17 -9
  2. templates/index.html +6 -47
app.py CHANGED
@@ -1,7 +1,8 @@
1
- from flask import Flask, render_template, Response
2
  import cv2
3
  import mediapipe as mp
4
  import numpy as np
 
5
 
6
  app = Flask(__name__)
7
 
@@ -46,14 +47,14 @@ def is_shoulder_press_correct(landmarks, mp_pose):
46
  else:
47
  return "Shoulder Press: Incorrect - Alignment", False
48
 
49
- # Video processing function (real-time camera frames)
50
- def process_camera():
51
- cap = cv2.VideoCapture(0) # Access the default camera
52
  count = 0
53
  rep_started = False
54
 
55
  with mp_pose.Pose(min_detection_confidence=0.5, min_tracking_confidence=0.5) as pose:
56
- while True:
57
  ret, frame = cap.read()
58
  if not ret:
59
  break
@@ -111,9 +112,16 @@ def process_camera():
111
  def index():
112
  return render_template('index.html')
113
 
114
- @app.route('/video_feed')
115
- def video_feed():
116
- return Response(process_camera(), mimetype='multipart/x-mixed-replace; boundary=frame')
 
 
 
 
 
 
 
117
 
118
  if __name__ == "__main__":
119
- app.run(debug=True, host="0.0.0.0")
 
1
+ from flask import Flask, render_template, request, Response
2
  import cv2
3
  import mediapipe as mp
4
  import numpy as np
5
+ import os
6
 
7
  app = Flask(__name__)
8
 
 
47
  else:
48
  return "Shoulder Press: Incorrect - Alignment", False
49
 
50
+ # Video processing function
51
+ def process_video(video_path):
52
+ cap = cv2.VideoCapture(video_path)
53
  count = 0
54
  rep_started = False
55
 
56
  with mp_pose.Pose(min_detection_confidence=0.5, min_tracking_confidence=0.5) as pose:
57
+ while cap.isOpened():
58
  ret, frame = cap.read()
59
  if not ret:
60
  break
 
112
  def index():
113
  return render_template('index.html')
114
 
115
+ @app.route('/upload', methods=['POST'])
116
+ def upload():
117
+ if 'video' not in request.files:
118
+ return "No video file uploaded", 400
119
+
120
+ video = request.files['video']
121
+ video_path = os.path.join('uploads', video.filename)
122
+ video.save(video_path)
123
+
124
+ return Response(process_video(video_path), mimetype='multipart/x-mixed-replace; boundary=frame')
125
 
126
  if __name__ == "__main__":
127
+ app.run(debug=True)
templates/index.html CHANGED
@@ -3,54 +3,13 @@
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Workout Reps Tracker</title>
7
- <style>
8
- body {
9
- font-family: Arial, sans-serif;
10
- margin: 0;
11
- padding: 0;
12
- background-color: #f4f4f4;
13
- }
14
- header {
15
- background-color: #333;
16
- color: white;
17
- text-align: center;
18
- padding: 1rem;
19
- }
20
- .container {
21
- text-align: center;
22
- padding: 2rem;
23
- }
24
- video {
25
- border: 5px solid #333;
26
- border-radius: 10px;
27
- max-width: 90%;
28
- height: auto;
29
- }
30
- footer {
31
- background-color: #333;
32
- color: white;
33
- text-align: center;
34
- padding: 1rem;
35
- position: fixed;
36
- bottom: 0;
37
- width: 100%;
38
- }
39
- </style>
40
  </head>
41
  <body>
42
- <header>
43
- <h1>Workout Reps Tracker</h1>
44
- </header>
45
- <div class="container">
46
- <h2>Real-Time Feedback</h2>
47
- <p>Track your workout posture and reps using the camera!</p>
48
- <!-- <video id="videoStream" autoplay playsinline></video> -->
49
- <br><br>
50
- <img src="/video_feed" alt="Camera Feed" id="cameraFeed">
51
- </div>
52
- <footer>x
53
- <p>&copy; 2024 Workout Tracker</p>
54
- </footer>
55
  </body>
56
  </html>
 
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Shoulder Press Detection</title>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  </head>
8
  <body>
9
+ <h1>Upload Your Shoulder Press Video</h1>
10
+ <form action="/upload" method="post" enctype="multipart/form-data">
11
+ <input type="file" name="video" accept="video/*" required>
12
+ <button type="submit">Upload and Analyze</button>
13
+ </form>
 
 
 
 
 
 
 
 
14
  </body>
15
  </html>