刚学习YOLOv11视频识别方法,分享一下,需要源码关注+私聊

1.效果

YOLOv11|视频识别|猕猴桃识别|零基础

2.主要代码

import cv2
from ultralytics import YOLO

if __name__ == '__main__':
    # 加载预训练模型
    model = YOLO('last.pt')  # 确保 'best.pt' 是有效的模型文件路径
    
    # 指定要处理的图像文件路径
    img_path = r"data\test\images\000151.png"
    
    # 使用 predict 方法处理图像(注意:方法名可能因库版本而异)
    # results = model(img_path)  # 这将返回一个包含 Detections 对象的列表
    cap=cv2.VideoCapture(img_path)
    检查是否有检测结果,并显示第一个图像的结果(如果有的话)
    while cap.isOpened():
        res, frame=cap.read()
        if res:
            results=model(frame)
            anotated_frame=results[0].plot()
            cv2.imshow(winname="best.pt",mat=anotated_frame)
            if cv2.waitKey(1)==27:
                break
        else:
            break
cap.release()
cv2.destroyAllWindows()
    # results[0].show()

3.需要关注+留言

Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐