randomshit11 commited on
Commit
b9eec86
·
verified ·
1 Parent(s): 0af1dd8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -22
app.py CHANGED
@@ -1,4 +1,3 @@
1
-
2
  import streamlit as st
3
  import cv2
4
  import mediapipe as mp
@@ -46,27 +45,27 @@ class VideoProcessor:
46
  self.model = build_model()
47
 
48
  def process_video(self, video_file):
49
- # Get the filename from the file object
50
- filename = video_file.name
51
- # Create a temporary file to write the contents of the uploaded video file
52
- temp_file = open(filename, 'wb')
53
- temp_file.write(video_file.read())
54
- temp_file.close()
55
- # Now we can open the video file using cv2.VideoCapture()
56
- cap = cv2.VideoCapture(filename)
57
- out_frames = []
58
- while cap.isOpened():
59
- ret, frame = cap.read()
60
- if not ret:
61
- break
62
- frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
63
- results = self.pose.process(frame_rgb)
64
- frame = self.draw_landmarks(frame, results)
65
- out_frames.append(frame)
66
- cap.release()
67
- # Remove the temporary file
68
- os.remove(filename)
69
- return out_frames
70
 
71
  def draw_landmarks(self, image, results):
72
  mp_drawing.draw_landmarks(image, results.pose_landmarks, mp_pose.POSE_CONNECTIONS,
 
 
1
  import streamlit as st
2
  import cv2
3
  import mediapipe as mp
 
45
  self.model = build_model()
46
 
47
  def process_video(self, video_file):
48
+ # Get the filename from the file object
49
+ filename = video_file.name
50
+ # Create a temporary file to write the contents of the uploaded video file
51
+ temp_file = open(filename, 'wb')
52
+ temp_file.write(video_file.read())
53
+ temp_file.close()
54
+ # Now we can open the video file using cv2.VideoCapture()
55
+ cap = cv2.VideoCapture(filename)
56
+ out_frames = []
57
+ while cap.isOpened():
58
+ ret, frame = cap.read()
59
+ if not ret:
60
+ break
61
+ frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
62
+ results = self.pose.process(frame_rgb)
63
+ frame = self.draw_landmarks(frame, results)
64
+ out_frames.append(frame)
65
+ cap.release()
66
+ # Remove the temporary file
67
+ os.remove(filename)
68
+ return out_frames
69
 
70
  def draw_landmarks(self, image, results):
71
  mp_drawing.draw_landmarks(image, results.pose_landmarks, mp_pose.POSE_CONNECTIONS,