You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

yolov8.py 708 B

1234567891011121314151617181920212223242526272829303132
  1. # Copyright 2020 Tencent
  2. # SPDX-License-Identifier: BSD-3-Clause
  3. import sys
  4. import cv2
  5. from ncnn.model_zoo import get_model
  6. from ncnn.utils import draw_detection_objects
  7. if __name__ == "__main__":
  8. if len(sys.argv) != 2:
  9. print("Usage: %s [imagepath]\n" % (sys.argv[0]))
  10. sys.exit(0)
  11. imagepath = sys.argv[1]
  12. m = cv2.imread(imagepath)
  13. if m is None:
  14. print("cv2.imread %s failed\n" % (imagepath))
  15. sys.exit(0)
  16. net = get_model(
  17. "yolov8s",
  18. target_size=640,
  19. prob_threshold=0.25,
  20. nms_threshold=0.45,
  21. num_threads=4,
  22. use_gpu=True,
  23. )
  24. objects = net(m)
  25. draw_detection_objects(m, net.class_names, objects)