import supervision as sv import cv2 import os from inference import get_model from ultralytics import YOLO print(sv.__version__) HOME = os.getcwd() # print(HOME) IMAGE_PATH = f"{HOME}//images//dog-3.jpeg" image = cv2.imread(IMAGE_PATH) # # 修正 cv2.imshow() 函数调用,添加窗口名称 # cv2.imshow('Display Image', image) # # 等待按键事件,防止窗口立即关闭 # cv2.waitKey(0) # # 关闭所有 OpenCV 窗口 # cv2.destroyAllWindows() # model = get_model(model_id="yolov8s-640") # result = model.infer(image)[0] # detections = sv.Detections.from_inference(result) model = YOLO("yolov8s.pt") result = model(image, verbose=False)[0] detections = sv.Detections.from_ultralytics(result) # print(detections) box_annotator = sv.BoxAnnotator() label_annotator = sv.LabelAnnotator() annotated_image = image.copy() annotated_image = box_annotator.annotate(annotated_image, detections=detections) annotated_image = label_annotator.annotate(annotated_image, detections=detections) sv.plot_image(image=annotated_image, size=(8, 8)) print('end of file')