YOLO基础教程(三):视频处理

本文介绍了使用YOLO进行视频处理的基础教程,通过代码展示了不同设置下视频帧率的测试结果,并说明如何简单修改代码以实现摄像头实时显示。通过将'cv2.VideoCapture('test.mp4')'替换为'cv2.VideoCapture(0)',可以将程序与第一个摄像头连接,实现1920x1080分辨率的实时视频流处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

与图形处理过程类似,毕竟视频是有一个个图形构成的,多的部分只是对视频的一些简单操作

源代码:

import cv2
from darkflow.net.build import TFNet
import numpy as np
import time

option = {
    'model': 'cfg/yolo.cfg',
    'load': 'bin/yolo.weights',
    'threshold': 0.3,
    'gpu': 0.7
}

tfnet = TFNet(option)

capture = cv2.VideoCapture('test.mp4')  # 读取视频
colors = [tuple(255 * np.random.rand(3)) for i in range(10)]  # 随机创建10中颜色,RGB形式
# 当视频打开时,进行处理
while capture.isOpened():
    stime = time.time()  # 计算起始时间
    ret, frame = capture.read()  # 读取每一帧,第一个参数是bool型的ret,其值为True或False,代表有没有读到图片,第二个参数是当前帧图像
    if ret:
        results = tfnet.return_predict(frame)  # 送入网络进行预测
        # 将 colors results 进行打包
        for color, result in zip(colors, results):
            tl = (result['topleft']['x'], result['topleft']['y'])
            br = (result['bottomright']['x'], result['bottomright']['y'])
            label = result['label']
            frame = cv2.rectangle(frame, tl, br, color, 3)
            frame
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值