PrashanthB461 commited on
Commit
06a63ac
·
verified ·
1 Parent(s): 9a1b6ee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -238,16 +238,20 @@ def process_video(video_data):
238
  continue
239
 
240
  results = model(frame, device=device)
 
241
  for result in results:
242
  for box in result.boxes:
243
  cls, conf = int(box.cls), float(box.conf)
244
- xywh = box.xywh.cpu().numpy()[0]
245
  label = CONFIG["VIOLATION_LABELS"].get(cls, f"class_{cls}")
 
 
 
 
246
  violation = {
247
  "frame": frame_count,
248
  "violation": label,
249
  "confidence": round(conf, 2),
250
- "bounding_box": [round(x, 2) for x in xywh],
251
  "timestamp": frame_count / video.get(cv2.CAP_PROP_FPS)
252
  }
253
  violations.append(violation)
 
238
  continue
239
 
240
  results = model(frame, device=device)
241
+ seen_violations = set() # Track unique violations in this frame
242
  for result in results:
243
  for box in result.boxes:
244
  cls, conf = int(box.cls), float(box.conf)
 
245
  label = CONFIG["VIOLATION_LABELS"].get(cls, f"class_{cls}")
246
+ if label in seen_violations:
247
+ continue # Skip if this violation type was already recorded in this frame
248
+ seen_violations.add(label)
249
+
250
  violation = {
251
  "frame": frame_count,
252
  "violation": label,
253
  "confidence": round(conf, 2),
254
+ "bounding_box": [round(x, 2) for x in box.xywh.cpu().numpy()[0]],
255
  "timestamp": frame_count / video.get(cv2.CAP_PROP_FPS)
256
  }
257
  violations.append(violation)