1.vc = cv2.VideoCapture('test.mp4') #进行视频的载入
2.vc.isOpened() # 判断载入的视频是否可以打开
3.ret, frame = vc.read() #进行单张图片的读取,ret的值为True或者Flase, frame表示读入的图片
4.cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) #表示将图片转换为灰度图
代码:
import cv2 vc = cv2.VideoCapture('test.mp4') if vc.isOpened():
# 读取视频中的一张图片
ret, frame = vc.read()
else:
ret = False while ret:
ret, frame = vc.read()
if ret == True:
img = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('test', img) if cv2.waitKey(10) & 0xFF == 27:
break