-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathyolo_darfklow.py
28 lines (21 loc) · 864 Bytes
/
yolo_darfklow.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
from darkflow.net.build import TFNet
from object_detector import ObjectDetector
class YOLODarkflowDetector(ObjectDetector):
def __init__(self, cfg_path, weights_path):
options = {"model": cfg_path,
"load": weights_path, "threshold": 0.01}
self.tfnet = TFNet(options)
def detect(self, frame, threshold=0.1):
results = self.tfnet.return_predict(frame)
return self.__boxes_coordinates(results, threshold)
def __boxes_coordinates(self, results, threshold):
boxes = []
for i in results:
if i['confidence'] <= threshold: continue
boxes.append([
(i['topleft']['x'], i['topleft']['y']),
(i['bottomright']['x'], i['bottomright']['y']),
i['confidence'],
i['label']
])
return boxes