-
Notifications
You must be signed in to change notification settings - Fork 0
/
dsc1.py
35 lines (31 loc) · 1.04 KB
/
dsc1.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
import cv2
from darkflow.net.build import TFNet
import numpy as np
options = {
"model": "cfg/yolo.cfg",
"load": "bin/yolo.weights",
"threshold": 0.2,
"gpu": 0.0,
}
tfnet = TFNet(options)
colors = [tuple(255 * np.random.rand(3)) for x in range(10)]
capture = cv2.VideoCapture("football.mp4")
while True:
ret, frame = capture.read()
if ret:
results = tfnet.return_predict(frame)
for color, result in zip(colors, results):
tl = (result["topleft"]["x"], result["topleft"]["y"])
br = (result["bottomright"]["x"], result["bottomright"]["y"])
label = result["label"]
confidence = result["confidence"]
text = "{}:{:.0f}%".format(label, confidence * 100)
frame = cv2.rectangle(frame, tl, br, color, 3)
frame = cv2.putText(
frame, text, tl, cv2.FONT_HERSHEY_DUPLEX, 1, (255, 255, 255), 2
)
cv2.imshow("output", frame)
if cv2.waitKey(1) & 0xFF == ord("q"):
break
capture.release()
cv2.destroyAllWindows()