import cv2 import imutils import os from detection import detect_person from draw import drawBoxOld, drawBoxNew ,distance import math MODEL_PATH = "Yolo" MIN_CONF = 0.3 loitering_threshold= 25 import time # added active_threshold=5 # added labelsPath = os.path.sep.join([MODEL_PATH, "coco.names"]) LABELS = open(labelsPath).read().strip().split("\n") weightsPath = os.path.sep.join([MODEL_PATH, "yolov3.weights"]) configPath = os.path.sep.join([MODEL_PATH, "yolov3.cfg"]) net = cv2.dnn.readNetFromDarknet(configPath, weightsPath) ln = net.getLayerNames() ln = [ln[i - 1] for i in net.getUnconnectedOutLayers()] vs = cv2.VideoCapture("input2.mp4") db=[] current_frame=0 person_id=0 while True: le=len(db) # added for it in range(le-1,-1,-1): # added if time.time()-db[it][2]>=active_threshold: # added db.pop(it) # added (grabbed,frame) = vs.read() if not grabbed: break frame = imutils.resize(frame, width=700) results = detect_person(frame, net, ln) for boxx in results : if len(db)==0: db.append([person_id,boxx[-1],time.time(),current_frame]);drawBoxNew(frame,boxx,current_frame,db) #modified added time.time() person_id+=1 else: maxd=99999 id=-1 # print(db) for temp in db: nearestDistance= distance(boxx[2][0],boxx[2][1],temp[1][0],temp[1][1]) if nearestDistance