導入に関しては、↓のサイトが分かり易いです。
from darkflow.net.build import TFNet
import matplotlib.pyplot as plt
import cv2
import sys
img_path = "./sample_img/dog.jpg"
options = {"model": "cfg/yolo.cfg", "load": "bin/yolo.weights", "threshold": 0.1, "gpu": 0.5}
tfnet = TFNet(options)
img = cv2.imread(img_path)
height, width, channels = img.shape
results = tfnet.return_predict(img)
for item in results:
tlx = item['topleft']['x']
tly = item['topleft']['y']
brx = item['bottomright']['x']
bry = item['bottomright']['y']
label = item['label']
conf = item['confidence']
if conf > 0.5:
cv2.rectangle(img, (tlx, tly), (brx, bry), (200,200,0), 2)
text = label + " " + ('%.2f' % conf)
cv2.putText(img,
text,
(tlx+10, tly-5),
cv2.FONT_HERSHEY_SIMPLEX,
0.6,
(244, 86, 66),
2)
plt.imshow(img)
plt.show()
cv2.imwrite("./result.jpg", img)