LoginSignup
1
5

More than 5 years have passed since last update.

[darkflow] YOLOv3 & tensorflow サンプル

Last updated at Posted at 2018-06-12

導入に関しては、↓のサイトが分かり易いです。

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)
1
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
5