AIProctoringSys / detector.py
Sazzz02's picture
Create detector.py
2cb83ee verified
raw
history blame contribute delete
416 Bytes
import cv2
from ultralytics import YOLO
import numpy as np
model = YOLO('yolov8n.pt') # Use lightweight model for Spaces
def detect_cheating(frame):
results = model(frame)
boxes = results[0].boxes.xyxy.cpu().numpy()
classes = results[0].boxes.cls.cpu().numpy()
num_persons = sum(1 for c in classes if int(c) == 0)
cheating_flag = num_persons > 1
return frame, cheating_flag, num_persons