1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import cv2
import matplotlib.pyplot as plt
import numpy as np

vc = cv2.VideoCapture('test.mp4')
#检测打开是否正确
if vc.isOpened():
open,frame = vc.read()
else:
open = False


while open:
ret,frame = vc.read()
if frame is None:
break
if ret ==True:
gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
cv2.imshow('result',gray)
if cv2.waitKey(1) &0xFF == 27:
break

vc.release()
cv2.destroyAllWindows()