当前位置:网站首页>视频转图像-cv2.VideoCapture()用法
视频转图像-cv2.VideoCapture()用法
2022-06-30 00:29:00 【宁然也】
用途:视频抽帧,视频图像化
1、cap = cv2.VideoCapture(0)
VideoCapture()中参数是0,表示打开笔记本的内置摄像头,参数是视频文件路径则打开
如cap = cv2.VideoCapture(“…/test.avi”)
# 参数是视频文件路径则打开
cap = cv2.VideoCapture('./RobustPCA_video_demo.avi')
2、ret,frame = cap.read()
cap.read()按帧读取视频,ret,frame是获cap.read()方法的两个返回值。
其中ret是布尔值,如果读取帧是正确的则返回True,如果文件读取到结尾,它的返回值就为False。
frame就是每一帧的图像,是个三维矩阵。
3、 cv2.destroyAllWindows() 用来删除窗口的,()里不指定任何参数,则删除所有窗口,删除特定的窗口,往()输入特定的窗口值。
4、调用release()释放摄像头,调用destroyAllWindows()关闭所有图像窗口。
import cv2
# cv2.VideoCapture 视频抽帧,视频图像化
# 参数是视频文件路径则打开
cap = cv2.VideoCapture('./RobustPCA_video_demo.avi')
all_frames = []
while(cap.isOpened()):
# ret是布尔值,如果读取帧正确返回true,当读到结尾会返回false
# frame是每一帧的图像,是个三维矩阵
ret, frame = cap.read()
if not ret :
break
all_frames.append(frame)
cap.release()
cv2.destroyAllWindows()
cv2.VideoCapture()用法及举例
cv2.waitKey()和cv2.destroyAllWindows()
边栏推荐
- 01 backpack problem
- Botu V16 changes the model and firmware version of PLC
- 字节、字、双字 关系
- Solr basic operation 11
- 初始I/O及其基本操作
- [uitableview] Pit 1: tableview:heightforheaderinsection: method does not execute
- [advanced C language] user defined type
- Flask web minimalist tutorial (III) - Sqlalchemy (part a)
- vim插件管理器vim-plug安装方法
- TP5查询AND和OR条件嵌套
猜你喜欢

What is the essential difference between get and post requests?

vsftp 与 TFTP 与 samba 与 nfs 复习

Interviewer: why does database connection consume resources? I can't even answer.. I was stunned!

Automatic integration: yescomusa, an overseas cross-border e-commerce, cooperates with cloud expansion to realize one-stop Automation Service
![[rust weekly library] Tokei - a utility for statistics of code lines and other information](/img/6c/4569cc0edaa01e4605c9c256193c31.png)
[rust weekly library] Tokei - a utility for statistics of code lines and other information

云呐|如何利用系统管理固定资产?如何进行固定资产管理?

Intermittent sampling and forwarding interference

Events in JS

js中的事件

学位论文的引用
随机推荐
The third bullet of wechat payment app application for refund
Rotating colored clover
云呐|固定资产系统管理的优势,固定资产管理系统有何特点
IO stream summary
What is the essential difference between get and post requests?
DataGridView上移 下移行
间歇采样转发干扰
Use of shortcut keys for idea tools
【PHP】PHP变量内存释放
Activity invitation | the Apache Doris community essay and speech solicitation activity has begun!
数据库学习笔记(SQL03)
Solr basic operation 10
There is no web-based development for the reward platform. Which is suitable for native development or mixed development?
Solr basic operations 9
C MDI open subform to remove automatically generated menu bar
How to write controller layer code gracefully?
MySQL foundation 2
Applying for let's encrypt SSL certificate with certbot
Solr basic operations 7
面试官:为什么数据库连接很消耗资源?我竟然答不上来。。一下懵了!