使用opencv\yolov10读取摄像头视频流,跳帧处理多目标识别

yolov10 模型下载

git clone https://www.modelscope.cn/THU-MIG/Yolov10.git

opencv 读取摄像头视频流

  • 直接读取电脑上插的摄像头
bash 复制代码
cap = cv2.VideoCapture(0)
ret, frame = cap.read()
print(cap.get(5), '<---------视频帧率')
  • 读取网络摄像头视频流
bash 复制代码
cap = cv2.VideoCapture('https://gbs.liveqing.com:10010/sms/34020000002020000001/hls/34020000001180000187_34020000001320000005/live.m3u8?token=y0Xj9Ad74-XnmgpFB6sV8sYiefo2')
ret, frame = cap.read()
print(cap.get(5), '<---------视频帧率')

跳帧: 视频处理需要大量的计算资源,尤其是在进行编码、解码、图像处理等复杂操作时。如果处理器的计算能力有限,可能无法实时处理每一帧,因此需要跳过一些帧以保证视频播放的流畅性

bash 复制代码
ret, frame = cap.read()
print(cap.get(5), '<---------视频帧率')
time_c = 0
while ret:
    # 读取视频帧
    time_c += 1
    # 设置每 10 帧输出一次
    if (time_c % 10) != 0:
        ret, frame = cap.read()
        yolo_img = frame
    else:
        ret, frame = cap.read()
        yolo_img = yolo_deal(frame)

yolo处理

bash 复制代码
# box_annotator = sv.BoxAnnotator() # 由于sv 0.22版本将取消BoxAnnotator,所以会提示警告 提示警告
box_annotator = sv.LabelAnnotator() # 没有边框
def yolo_deal(image):
    results = model(source=image, conf=0.5, verbose=False)[0]
    detections = sv.Detections.from_ultralytics(results)


    category_dict = {
        0: 'person', 1: 'bicycle', 2: 'car', 3: 'motorcycle', 4: 'airplane', 5: 'bus',
        6: 'train', 7: 'truck', 8: 'boat', 9: 'traffic light', 10: 'fire hydrant',
        11: 'stop sign', 12: 'parking meter', 13: 'bench', 14: 'bird', 15: 'cat',
        16: 'dog', 17: 'horse', 18: 'sheep', 19: 'cow', 20: 'elephant', 21: 'bear',
        22: 'zebra', 23: 'giraffe', 24: 'backpack', 25: 'umbrella', 26: 'handbag',
        27: 'tie', 28: 'suitcase', 29: 'frisbee', 30: 'skis', 31: 'snowboard',
        32: 'sports ball', 33: 'kite', 34: 'baseball bat', 35: 'baseball glove',
        36: 'skateboard', 37: 'surfboard', 38: 'tennis racket', 39: 'bottle',
        40: 'wine glass', 41: 'cup', 42: 'fork', 43: 'knife', 44: 'spoon', 45: 'bowl',
        46: 'banana', 47: 'apple', 48: 'sandwich', 49: 'orange', 50: 'broccoli',
        51: 'carrot', 52: 'hot dog', 53: 'pizza', 54: 'donut', 55: 'cake',
        56: 'chair', 57: 'couch', 58: 'potted plant', 59: 'bed', 60: 'dining table',
        61: 'toilet', 62: 'tv', 63: 'laptop', 64: 'mouse', 65: 'remote', 66: 'keyboard',
        67: 'cell phone', 68: 'microwave', 69: 'oven', 70: 'toaster', 71: 'sink',
        72: 'refrigerator', 73: 'book', 74: 'clock', 75: 'vase', 76: 'scissors',
        77: 'teddy bear', 78: 'hair drier', 79: 'toothbrush'
    }

    labels = [
        f"{category_dict[class_id]} {confidence:.2f}"
        for class_id, confidence in zip(detections.class_id, detections.confidence)
    ]
    annotated_image = box_annotator.annotate(
        image.copy(), detections=detections, labels=labels
    )
    return annotated_image

完整代码链接:

demo

相关推荐
serve the people8 小时前
tensorflow Keras Sequential 模型
人工智能·tensorflow·keras
RebeccaGuan08088 小时前
泛微.采知连知识管理平台深度应用DeepSeek,自动采集数据,让问答更安全·准确
人工智能·智能问答·知识管理·deepseek·知识采集
元让_vincent8 小时前
论文Review 3DGS综述 | 南京大学 | 3DGS Survey, Technologies Challenges and Opportunities |(二)扩展、模块增强、其他技术讨论挑战
人工智能·数据挖掘·综述·3dgs
六行神算API-天璇8 小时前
数字人“个性化”背后的玄机:大模型微调与RAG实战解析
大数据·人工智能
永远都不秃头的程序员(互关)8 小时前
大模型Agent核心架构拆解:从原理到可落地的智能任务规划器开发
人工智能
百***24378 小时前
GPT-5.2核心优势详解与极速接入指南(含与GPT-5.1对比)
人工智能·gpt
十铭忘8 小时前
SAM2跟踪的理解9——mask decoder
人工智能·计算机视觉
Deepoch8 小时前
低幻觉AI:重塑科研与教育领域的可信智能新范式
大数据·人工智能·机器学习·机器人·具身模型·deepoc·低幻觉ai
Data_Journal8 小时前
Puppeteer vs. Playwright —— 哪个更好?
运维·人工智能·爬虫·媒体·静态代理