from PIL import Image
from ultralytics import YOLO
# Load a pretrained YOLOv8n model
model = YOLO('best.pt')
# Run inference on 'bus.jpg'
results = model('00000003.tif') # results list
# Show the results
for r in results:
im_array = r.plot() # plot a BGR numpy array of predictions
im = Image.fromarray(im_array[..., ::-1]) # RGB PIL image
#im.show() # show image
im.save('results.jpg') # save image
YOLOV8保存处理后的图像
最新推荐文章于 2024-04-15 18:13:30 发布
本文展示了如何使用Python的PIL库和ultralytics的YOLOv8模型进行图像文件(如bus.jpg和tif格式)的预训练对象检测,包括加载模型、运行预测、显示结果并保存图片。
摘要由CSDN通过智能技术生成