惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Blog of Author Tim Ferriss
S
Securelist
D
Docker
The Register - Security
The Register - Security
GbyAI
GbyAI
Recorded Future
Recorded Future
Engineering at Meta
Engineering at Meta
Stack Overflow Blog
Stack Overflow Blog
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
罗磊的独立博客
博客园 - 【当耐特】
F
Full Disclosure
WordPress大学
WordPress大学
腾讯CDC
小众软件
小众软件
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
SecWiki News
SecWiki News
L
Lohrmann on Cybersecurity
I
InfoQ
MyScale Blog
MyScale Blog
量子位
Cyberwarzone
Cyberwarzone
博客园 - 三生石上(FineUI控件)
The Hacker News
The Hacker News
F
Fortinet All Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Jina AI
Jina AI
博客园_首页
H
Help Net Security
K
Kaspersky official blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Webroot Blog
Webroot Blog
Blog — PlanetScale
Blog — PlanetScale
V
Vulnerabilities – Threatpost
Y
Y Combinator Blog
The Cloudflare Blog
P
Proofpoint News Feed
V
Visual Studio Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tailwind CSS Blog
爱范儿
爱范儿
P
Privacy International News Feed
Security Archives - TechRepublic
Security Archives - TechRepublic
The GitHub Blog
The GitHub Blog
C
Cybersecurity and Infrastructure Security Agency CISA
B
Blog RSS Feed

博客园 - 白桦的天空

python+uwsgi警告 树莓派设置为竖屏显示 树莓派无桌面系统(RaspberryPI Lite)启动自动打开Chromium-Browser的具体方法 antui-alipay风格的移动网页设计 移动网页字体大小随着页面自动切换 自定义树莓派开机启动画面-plymouth版本 树莓派py文件自动运行 树莓派VLC获取实时视频流 一个标准的pygame例子 pygame镜像输出 python中使用pylet实现异屏输出 选择金额充值的选中css样式 Debian 无桌面+QT运行环境 手机外部浏览器跳转支付宝内置浏览器例子 前端动态获取后台处理进度显示在进度条上 Ventoy 多合一启动盘制作工具神器 - 将多个系统 Win/PE/Linux 镜像装在1个U盘里 pygame和pywebview配合做界面 通过websocket接口获取数据实时更新数据表 python监听麦克风并通过websocket输出音频数据峰值目的是绘制音频曲线
如何使用 opencv-python 提取视频每一帧的图片?
白桦的天空 · 2023-08-04 · via 博客园 - 白桦的天空

参考:https://blog.csdn.net/u013066730/article/details/126356627

获取视频(创建 VideoCapture 对象)

使用 cv2.VideoCapture 类

Args:

  • filename – 文件路径;
  • device – 视频设备id ,若只有一个摄像头可以填 0,表示打开默认摄像头;
    vc = cv2.VideoCapture(filename)
    

    检验 VideoCapture 对象是否创境成功

    使用 VideoCapture 对象的 isOpened 方法

    # determine whether to open normally
    if vc.isOpened():
        ret, frame = vc.read()
    else:
        ret = False
    

    若成功,返回 True。

    按帧读取视频

    使用 VideoCapture 对象的 read 方法

    使用 VideoCapture 对象的 read 方法按帧读取视频,ret, frame 是 read 方法的两个返回值 ,其中 ret 是布尔值,如果能正确读取帧,则返回 True;如果文件读取到结尾,它的返回值就为 False。frame 就是每一帧的图像,是一个三维矩阵。

    # loop read video frame
    while ret:
        ret, frame = vc.read()
    

    保存图片

    使用 cv2.imwrite() 函数

    第一个参数是文件名,第二个参数是图片资源。

  • cv2.imwrite(image_path, image)