Imran606's picture
Upload 82 files
3837d65
import numpy as np
import torch
import cv2
import pandas as pd
import streamlit as st
#displaying a local video file
#reading the file
f = st.text_input("Input Your Image Path",key="placeholder")
#
cap1=cv2.VideoCapture(f)
if st.button('Cheating Detection'):
try:
def detect():
path='/usr/local/lib/python3.10/dist-packages/yolo0vs5/yolov5s-int8.tflite'
#count=0
custom = 'yolov5s'
model = torch.hub.load('/usr/local/lib/python3.10/dist-packages/yolovs5', custom, path,source='local',force_reload=True)
b=model.names[0] = 'person'
size=416
count=0
counter=0
color=(0,0,255)
cy1=250
offset=6
pt1 = (120, 100)
pt2 = (980, 1150)
color = (0, 255, 0)
pt3 = (283, 103)
pt4 = (1500, 1150)
cy2 = 500
color = (0, 255, 0)
cheating = "Cheating"
while True:
ret,img=cap1.read()
count += 1
if count % 4 != 0:
continue
img=cv2.resize(img, (600,500))
cv2.line(img, pt1, pt2,color,2)
cv2.line(img, pt3, pt4,color,2)
results = model(img,size)
components = results.pandas().xyxy[0]
for index, row in results.pandas().xyxy[0].iterrows():
print(row)
x1 = int(row['xmin'])
y1 = int(row['ymin'])
x2 = int(row['xmax'])
y2 = int(row['ymax'])
confidence = (row['confidence'])
obj = (row['class'])
dff = {'xmin':x1,'ymin':y1,'xmax':x2,'ymax':y2,'confidence':confidence,'Object':obj}
if obj == 0:
cv2.rectangle(img,(x1,y1),(x2,y2),(0,0,255),2)
rectx1,recty1 = ((x1+x2)/2,(y1+y2)/2)
rectcenter = int(rectx1),int(recty1)
cx = rectcenter[0]
cy = rectcenter[1]
cv2.circle(img,(cx,cy),3,(0,255,0),-1)
cv2.putText(img,str(b), (x1,y1), cv2.FONT_HERSHEY_PLAIN,2,(255,255,255),2)
if cy<(cy1+offset) and cy>(cy1-offset):
counter+=1
cv2.line(img, pt1, pt2,(0, 0, 255),2)
if cy<(cy2+offset) and cy>(cy2-offset):
cv2.line(img, pt3, pt4,(0, 0, 255),2)
cv2.imshow("IMG",img)
if cv2.waitKey(1)&0xFF==27:
break
cap1.release()
cv2.destroyAllWindows()
detect()
except:
pass