1.opencv读取视频内容
- 读取一个视频内容分为下面几部
1.建立一个函数
读取视频的每一帧:
capture = cv.VideoCapture(0)#视频的读取
2.写一个while循环,将视频的每一帧显示出来
while (True):
ret, frame = capture.read() # 视频当中的每一帧
frame = cv.flip(frame, 1) # 镜像变换
cv.imshow("video", frame) # 循环显示出来
c = cv.waitKey(50)#延时50msx
if c == 27:
break
最终程序
'''
本程序是读取视频读取图像的内容
'''
import cv2 as cv#导入opencv包并且命名为cv
def video_demo(): # 定义一个视频函数
capture = cv.VideoCapture(0)#视频的读取
while (True):
ret, frame = capture.read() # 视频当中的每一帧
frame = cv.flip(frame, 1) # 镜像变换
cv.imshow("video", frame) # 循环显示出来
c = cv.waitKey(50)#延时50msx
if c == 27:
break
video_demo()
cv.waitKey(0)#如果不添加则会在IDLE中执行窗口直接无响应。在命令行中执行的话,则是一闪而过。
cv.destroyAllWindows()#释放窗口