randomshit11 commited on
Commit
ef2a26a
·
verified ·
1 Parent(s): 823472a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -19
app.py CHANGED
@@ -60,32 +60,31 @@ class VideoProcessor:
60
  self.pose = mp_pose.Pose(min_detection_confidence=0.5, min_tracking_confidence=0.5)
61
 
62
  def process_video(self, video_file):
63
- # Get the filename from the file object
64
- filename = "temp_video.mp4"
65
- # Open the file and read its contents
66
- with open(filename, 'wb') as temp_file:
67
- temp_file.write(video_file.read())
68
- # Process the video and save the processed video to a new file
69
- output_filename = "processed_video.mp4"
70
- cap = cv2.VideoCapture(filename)
71
- frame_width = int(cap.get(3))
72
- frame_height = int(cap.get(4))
73
- out = cv2.VideoWriter(output_filename, cv2.VideoWriter_fourcc(*'h264'), 30, (frame_width, frame_height))
74
  while cap.isOpened():
75
  ret, frame = cap.read()
76
  if not ret:
77
  break
78
- frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
79
- results = self.pose.process(frame_rgb)
80
- processed_frame = self.process_frame(frame, results)
81
- out.write(processed_frame)
 
82
  cap.release()
83
- out.release()
84
- # Remove the temporary file
85
- os.remove(filename)
86
- # Return the path to the processed video file
 
87
  return output_filename
88
 
 
89
 
90
  def process_frame(self, frame, results):
91
  # Process the frame using the `process` function
 
60
  self.pose = mp_pose.Pose(min_detection_confidence=0.5, min_tracking_confidence=0.5)
61
 
62
  def process_video(self, video_file):
63
+ cap = cv2.VideoCapture(video_file.name) # Open the video file
64
+ height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
65
+ width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
66
+ fps = cap.get(cv2.CAP_PROP_FPS)
67
+
68
+ frames = []
69
+
 
 
 
 
70
  while cap.isOpened():
71
  ret, frame = cap.read()
72
  if not ret:
73
  break
74
+ rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
75
+ # Process the frame (replace this with your processing logic)
76
+ processed_frame = self.process_frame(rgb_frame)
77
+ frames.append(processed_frame) # Append processed frame
78
+
79
  cap.release()
80
+
81
+ # Write processed frames to video
82
+ output_filename = "processed_video.mp4"
83
+ mediapy.write_video(output_filename, frames, fps=fps)
84
+
85
  return output_filename
86
 
87
+
88
 
89
  def process_frame(self, frame, results):
90
  # Process the frame using the `process` function