**
一、调用摄像头并输出画面
** 代码如下
import cv2 as cv
def video_demo():
capture = cv.VideoCapture(0)
while (True):
ret, frame = capture.read()
frame = cv.flip(frame, 1)
cv.imshow("image", frame)
c = cv.waitKey(5)
if c == 27:
break
video_demo()
cv.waitKey(0);
cv.destroyAllWindows()
二、输出视频文件
代码如下
def video_demo():
cv.namedWindow("video", 0)
cv.resizeWindow("video", 1000, 600)
while True:
ret, frame = capture.read()
cv.imshow("video", frame)
cv.waitKey(1)
if cv.waitKey(5) == 27:
break
ret, frame = capture.read()
capture.release()
video_demo()
cv.destroyAllWindows()
|