-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathuffDetectSocial.py
72 lines (56 loc) · 1.84 KB
/
uffDetectSocial.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
############################
# Deteccao de Distanciamento Social
# Autor: Alex Salgado
#
# Para executar, usar o script start.sh
############################
import cv2
import numpy as np
import uffBBoxYolo as mydet
import argparse
import time
import imutils
import testHomogr as uffHomg
# parametros de entrada
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--input", type=str, default="",
help="defina o caminho para o video")
args = vars(ap.parse_args())
classesFile = "cnn/coco.names"
classNames = []
with open(classesFile, 'rt') as f:
classNames = f.read().rstrip('\n').split('\n')
print(classNames)
#modelConfiguration = "cnn/yolov3-tiny.cfg"
#modelWeights = "cnn/yolov3-tiny.weights"
modelConfiguration = "cnn/yolov3-320.cfg"
modelWeights = "cnn/yolov3-320.weights"
net = cv2.dnn.readNetFromDarknet(modelConfiguration, modelWeights)
net.setPreferableBackend(cv2.dnn.DNN_BACKEND_OPENCV)
net.setPreferableTarget(cv2.dnn.DNN_TARGET_CPU)
#parametros da deteccao
whT = 320
confThreshold = 0.5
nmsThreshold = 0.3
size_frame = 900
# inicializando video ou camera
print("[INFO] accessing video stream...")
cap = cv2.VideoCapture(args["input"] if args["input"] else 0)
while True:
prev_time = time.time()
success, img = cap.read()
# Resize na imagem
img = imutils.resize(img, width=int(size_frame))
#img = uffHomg.transform(img)
blob = cv2.dnn.blobFromImage(img, 1 / 255, (whT, whT), [0, 0, 0], 1, crop=False)
net.setInput(blob)
layersNames = net.getLayerNames()
outputNames = [(layersNames[i[0]-1]) for i in net.getUnconnectedOutLayers()]
outputs = net.forward(outputNames)
# detecta distancia social
mydet.findSocialDistance(outputs, img,confThreshold,nmsThreshold,classNames)
cv2.imshow('Image', img)
key = cv2.waitKey(1) & 0xFF
# tecle `q` para sair
if key == ord("q"):
break