-
Notifications
You must be signed in to change notification settings - Fork 164
/
docker_demo.py
34 lines (26 loc) · 1.14 KB
/
docker_demo.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
from pydarknet import Detector, Image
import cv2
import os
import time
if __name__ == "__main__":
net = Detector(bytes("cfg/yolov3.cfg", encoding="utf-8"), bytes("weights/yolov3.weights", encoding="utf-8"), 0,
bytes("cfg/coco.data", encoding="utf-8"))
input_files = os.listdir("input")
for file_name in input_files:
if not file_name.lower().endswith(".jpg"):
continue
print("File:", file_name)
img = cv2.imread(os.path.join("input", file_name))
img2 = Image(img)
start_time = time.time()
results = net.detect(img2)
end_time = time.time()
print("Elapsed Time:", end_time - start_time)
for cat, score, bounds in results:
x, y, w, h = bounds
print(f"{cat} at [{x},{y}]: Confidence: {score}")
cv2.rectangle(img, (int(x - w / 2), int(y - h / 2)), (int(x + w / 2), int(y + h / 2)), (255, 0, 0),
thickness=2)
cv2.putText(img, cat, (int(x), int(y)), cv2.FONT_HERSHEY_DUPLEX, 4, (0, 0, 255), thickness=2)
cv2.imwrite(os.path.join("output", file_name), img)
print()