YOLO-v8-seg实例分割使用

最近需要实例分割完成一些任务,一直用的SAM(segment anything)速度慢,找一个轻量分割模型。

1. YOLO-v8-seg使用

git clone https://github.com/ultralytics/ultralytics.git

cd ultralytics

vim run.py

from ultralytics import YOLO

# Load a model
model = YOLO('yolov8l-seg.pt')  # load an official model

# Predict with the model
results = model('test.jpg')  # predict on an image

就这么几行,这就行了?代码量也太少了。

2 效果

效果也还不错

速度:

3. 对结果results的解析

可以看官方详细介绍:预测 -Ultralytics YOLOv8 文档

img = cv2.imread(img_path)
imgray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
print(img.shape)
for result in results:
    boxes = result.boxes  # Boxes object for bounding box outputs
    masks = result.masks  # Masks object for segmentation masks outputs
    for mask in masks:
        print(mask.xy)
        print(type(mask.xy))
        points = np.array(mask.xy, dtype=np.int32)
        cv2.polylines(img, [points], isClosed=True, color=(0, 255, 0), thickness=2)
    keypoints = result.keypoints  # Keypoints object for pose outputs
    probs = result.probs  # Probs object for classification outputs
    #result.show()  # display to screen
    result.save(filename='result.jpg')  # save to disk
cv2.imwrite('test.jpg',img)

很好用,希望对你有帮助!

THE END!

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值