Sazzz02 commited on
Commit
2cb83ee
·
verified ·
1 Parent(s): 7ae10b8

Create detector.py

Browse files
Files changed (1) hide show
  1. detector.py +15 -0
detector.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ from ultralytics import YOLO
3
+ import numpy as np
4
+
5
+ model = YOLO('yolov8n.pt') # Use lightweight model for Spaces
6
+
7
+ def detect_cheating(frame):
8
+ results = model(frame)
9
+ boxes = results[0].boxes.xyxy.cpu().numpy()
10
+ classes = results[0].boxes.cls.cpu().numpy()
11
+
12
+ num_persons = sum(1 for c in classes if int(c) == 0)
13
+ cheating_flag = num_persons > 1
14
+
15
+ return frame, cheating_flag, num_persons