-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetectVideo.py
More file actions
38 lines (30 loc) · 1.04 KB
/
Copy pathdetectVideo.py
File metadata and controls
38 lines (30 loc) · 1.04 KB
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
import cv2
# img = cv2.imread("./test2.png")
video = cv2.VideoCapture(0)
classNames = []
classFile = "coco.name"
with open(classFile, 'rt') as f:
classNames= f.read().rstrip("\n").split("\n")
#print(classNames)
weightPath = "model/frozen_inference_graph.pb"
configPath = "model/ssd_mobilenet_v3_large_coco_2020_01_14.pbtxt"
net = cv2.dnn_DetectionModel(weightPath, configPath)
net.setInputSize(320,320)
net.setInputScale(1.0/ 127.5)
net.setInputMean((127.5, 127.5, 127.5))
net.setInputSwapRB(True)
while True:
ret, frame = video.read()
cv2.imshow("frame", frame)
classIds, confs, bboxs = net.detect(frame, confThreshold=0.5)
for classId, conf , bbox in zip(classIds, confs, bboxs):
try:
cv2.rectangle(frame, bbox, color=(0,255,0))
cv2.putText(frame,classNames[classId-1], (bbox[0]+10, bbox[1]-10), cv2.FONT_HERSHEY_COMPLEX, 0.8, (0,255,0),1)
except:
print("Object not in dataset...")
if cv2.waitKey(1)==ord("q"):
break
video.release()
cv2.destroyAllWindows()
cv2.waitKey(0)