JrEasy commited on
Commit
0d5c22d
·
verified ·
1 Parent(s): 57f956e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -6
app.py CHANGED
@@ -80,7 +80,7 @@ def process_video(input_video):
80
 
81
  fps = cap.get(cv2.CAP_PROP_FPS)
82
 
83
- # Define the output video path in the current directory
84
  output_video_path = os.path.join(os.getcwd(), "processed_video.mp4")
85
 
86
  writer = imageio.get_writer(output_video_path, fps=fps, codec="h264")
@@ -102,11 +102,14 @@ def process_video(input_video):
102
 
103
  # Convert the resized frame to grayscale
104
  gray_frame = cv2.cvtColor(resized_frame, cv2.COLOR_BGR2GRAY)
105
- # Convert grayscale to 3 channels (RGB format)
106
- input_frame = cv2.merge([gray_frame, gray_frame, gray_frame]) # Convert grayscale to 3 channels
107
 
 
 
 
 
108
  results = model.predict(input_frame)
109
 
 
110
  for result in results:
111
  for box in result.boxes:
112
  if box.conf[0] >= confidence_threshold:
@@ -122,14 +125,18 @@ def process_video(input_video):
122
  timestamps.append(timestamp)
123
  classes_detected.append(class_id)
124
 
125
- # Ensure the frame is in RGB format before appending to the writer
126
  rgb_frame = cv2.cvtColor(resized_frame, cv2.COLOR_BGR2RGB)
127
-
128
- # Ensure the frame has the correct shape (640x640x3)
 
 
 
129
  if rgb_frame.shape[2] != 3:
130
  print(f"Warning: Unexpected frame shape {rgb_frame.shape}, adjusting...")
131
  rgb_frame = cv2.cvtColor(resized_frame, cv2.COLOR_BGR2RGB)
132
 
 
133
  writer.append_data(rgb_frame)
134
 
135
  cap.release()
@@ -145,6 +152,7 @@ def process_video(input_video):
145
 
146
 
147
 
 
148
  def process_image(input_image):
149
  # Convert image from RGB to BGR for OpenCV processing
150
  bgr_frame = cv2.cvtColor(input_image, cv2.COLOR_RGB2BGR)
 
80
 
81
  fps = cap.get(cv2.CAP_PROP_FPS)
82
 
83
+ # Define the output video path
84
  output_video_path = os.path.join(os.getcwd(), "processed_video.mp4")
85
 
86
  writer = imageio.get_writer(output_video_path, fps=fps, codec="h264")
 
102
 
103
  # Convert the resized frame to grayscale
104
  gray_frame = cv2.cvtColor(resized_frame, cv2.COLOR_BGR2GRAY)
 
 
105
 
106
+ # Convert grayscale to RGB (3 channels)
107
+ input_frame = cv2.merge([gray_frame, gray_frame, gray_frame])
108
+
109
+ # Get predictions from the model
110
  results = model.predict(input_frame)
111
 
112
+ # Drawing bounding boxes and adding text
113
  for result in results:
114
  for box in result.boxes:
115
  if box.conf[0] >= confidence_threshold:
 
125
  timestamps.append(timestamp)
126
  classes_detected.append(class_id)
127
 
128
+ # Convert the frame to RGB (BGR to RGB)
129
  rgb_frame = cv2.cvtColor(resized_frame, cv2.COLOR_BGR2RGB)
130
+
131
+ # Log the shape of the frame to check it's correct
132
+ print(f"Frame shape: {rgb_frame.shape}") # This should print (640, 640, 3)
133
+
134
+ # Check if the frame has 3 channels (RGB)
135
  if rgb_frame.shape[2] != 3:
136
  print(f"Warning: Unexpected frame shape {rgb_frame.shape}, adjusting...")
137
  rgb_frame = cv2.cvtColor(resized_frame, cv2.COLOR_BGR2RGB)
138
 
139
+ # Append the frame to the video writer
140
  writer.append_data(rgb_frame)
141
 
142
  cap.release()
 
152
 
153
 
154
 
155
+
156
  def process_image(input_image):
157
  # Convert image from RGB to BGR for OpenCV processing
158
  bgr_frame = cv2.cvtColor(input_image, cv2.COLOR_RGB2BGR)