import cv2
'''先把一个视频分拆成多个图片'''
读取视频
cap = cv2.VideoCapture('datas/d297cfe2f4eee3397d89490c029e382d.mp4')
c = 1
while cap.isOpened():
ret,frame = cap.read()
if not ret:#这两行为了作完正常结束,没有的话会报错
break
frame = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)#这行是为了改变颜色
cv2.imwrite('image/IMG_0'+str(c)+'.jpg',frame)#需要先创建一个空文件夹image
c = c+1
cv2.waitKey(1)