tensorboy0101 commited on
Commit
436efc8
·
verified ·
1 Parent(s): 70c768b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -44
app.py CHANGED
@@ -1,44 +1,55 @@
1
- from flask import Flask, render_template, Response
2
- import cv2
3
- import mediapipe as mp
4
-
5
- app = Flask(__name__)
6
-
7
- # Initialize webcam and Mediapipe Pose detection
8
- mp_pose = mp.solutions.pose
9
- pose = mp_pose.Pose()
10
- cap = cv2.VideoCapture(0, cv2.CAP_DSHOW) # Use DirectShow for better camera compatibility
11
-
12
- def generate_frames():
13
- while True:
14
- success, frame = cap.read()
15
- if not success:
16
- break
17
- else:
18
- # Convert BGR to RGB for Mediapipe processing
19
- rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
20
- results = pose.process(rgb_frame)
21
-
22
- # Draw pose landmarks
23
- if results.pose_landmarks:
24
- mp.solutions.drawing_utils.draw_landmarks(
25
- frame, results.pose_landmarks, mp_pose.POSE_CONNECTIONS
26
- )
27
-
28
- # Encode frame to JPEG format
29
- ret, buffer = cv2.imencode('.jpg', frame)
30
- frame = buffer.tobytes()
31
-
32
- yield (b'--frame\r\n'
33
- b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
34
-
35
- @app.route('/')
36
- def index():
37
- return render_template('index.html') # HTML page to display video
38
-
39
- @app.route('/video')
40
- def video():
41
- return Response(generate_frames(), mimetype='multipart/x-mixed-replace; boundary=frame')
42
-
43
- if __name__ == "__main__":
44
- app.run(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+
3
+ import qdarktheme
4
+ from PyQt5.QtWidgets import QApplication
5
+
6
+ from app_controllers.controller import Controller
7
+ from app_models.model import Model
8
+ from app_views.view import View
9
+
10
+ model_name = "small640.pt"
11
+
12
+
13
+ class App:
14
+ def __init__(self):
15
+ super().__init__()
16
+ self.model = Model(model_name)
17
+ self.view = View(self.model)
18
+ self.controller = Controller(self.model, self.view)
19
+ print("All modules loaded")
20
+
21
+
22
+ if __name__ == '__main__':
23
+ if len(sys.argv) > 2:
24
+ print("Error: Exactly one argument is expected")
25
+ sys.exit(1)
26
+ elif len(sys.argv) == 1:
27
+ print("Info: Loading default inference model: {}".format(model_name))
28
+ else:
29
+ model_name = sys.argv[1]
30
+ qdarktheme.enable_hi_dpi()
31
+ app = QApplication([])
32
+ qdarktheme.setup_theme('dark')
33
+ # update global stylesheet
34
+ current_stylesheet = app.styleSheet()
35
+ updated_stylesheet = current_stylesheet + """
36
+ QSlider {background-color: #323844;}
37
+ QGroupBox {background-color: #323844;}
38
+ QLabel {font-weight: bold;}
39
+ QPushButton{font-weight: bold;}
40
+ QCheckBox {font-weight: bold;}
41
+ QRadioButton {font-weight: bold;}
42
+ QComboBox {font-weight: bold;}
43
+ QToolTip {
44
+ background-color: #323844;
45
+ color: white;
46
+ font-size: 12px;
47
+ border: 1px solid #aaa;
48
+ border-radius: 4px;
49
+ padding: 5px;
50
+ }
51
+ """
52
+ app.setStyleSheet(updated_stylesheet)
53
+ window = App()
54
+ window.view.show()
55
+ sys.exit(app.exec())