Sanshruth commited on
Commit
98b6de7
·
verified ·
1 Parent(s): 150bca2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -211,13 +211,15 @@ def process_video(confidence_threshold=0.5, selected_classes=None, stream_url=No
211
  errors.append("Error: Could not read frame from the stream.")
212
  break
213
 
 
 
 
214
  # Resize the frame for processing
215
- height, width = frame.shape[:2]
216
- new_width = int(width * resolution_scale)
217
- new_height = int(height * resolution_scale)
218
  resized_frame = cv2.resize(frame, (new_width, new_height))
219
 
220
- # Perform object tracking with confidence threshold
221
  results = model.track(resized_frame, persist=True, conf=confidence_threshold)
222
 
223
  if results[0].boxes.id is not None:
@@ -229,7 +231,7 @@ def process_video(confidence_threshold=0.5, selected_classes=None, stream_url=No
229
  for box, cls, t_id, conf in zip(boxes, clss, track_ids, confs):
230
  if conf >= confidence_threshold and model.names[cls] in selected_classes:
231
  # Scale the bounding box back to the original resolution
232
- box = box * (width / new_width)
233
  # Check if the object crosses the line
234
  if is_object_crossing_line(box, line_params) and t_id not in crossed_objects:
235
  crossed_objects[t_id] = True
@@ -241,7 +243,7 @@ def process_video(confidence_threshold=0.5, selected_classes=None, stream_url=No
241
  # Visualize the results with bounding boxes, masks, and IDs on the original frame
242
  annotated_frame = results[0].plot(img=frame)
243
 
244
- # Draw the angled line on the frame
245
  draw_angled_line(annotated_frame, line_params, color=(0, 255, 0), thickness=2)
246
 
247
  # Display the count on the frame with a modern look
 
211
  errors.append("Error: Could not read frame from the stream.")
212
  break
213
 
214
+ # Get the original frame dimensions
215
+ original_height, original_width = frame.shape[:2]
216
+
217
  # Resize the frame for processing
218
+ new_width = int(original_width * resolution_scale)
219
+ new_height = int(original_height * resolution_scale)
 
220
  resized_frame = cv2.resize(frame, (new_width, new_height))
221
 
222
+ # Perform object tracking with confidence threshold on the resized frame
223
  results = model.track(resized_frame, persist=True, conf=confidence_threshold)
224
 
225
  if results[0].boxes.id is not None:
 
231
  for box, cls, t_id, conf in zip(boxes, clss, track_ids, confs):
232
  if conf >= confidence_threshold and model.names[cls] in selected_classes:
233
  # Scale the bounding box back to the original resolution
234
+ box = box * (original_width / new_width)
235
  # Check if the object crosses the line
236
  if is_object_crossing_line(box, line_params) and t_id not in crossed_objects:
237
  crossed_objects[t_id] = True
 
243
  # Visualize the results with bounding boxes, masks, and IDs on the original frame
244
  annotated_frame = results[0].plot(img=frame)
245
 
246
+ # Draw the angled line on the original frame
247
  draw_angled_line(annotated_frame, line_params, color=(0, 255, 0), thickness=2)
248
 
249
  # Display the count on the frame with a modern look