python利用opencv实现保存、播放视频-创新互联
python利用opencv实现保存、播放视频?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
1.首先创建一个VideoCapture对象,它的参数包含两种:
- 设备索引,指定摄像机的编号。
- 视频文件的名称。
2.逐帧捕捉。
3.释放捕捉物。
import numpy as np import cv2 as cv cap = cv.VideoCapture(0) if not cap.isOpened(): print("Cannot open camera") exit() while True: # Capture frame-by-frame ret, frame = cap.read() # if frame is read correctly ret is True if not ret: print("Can't receive frame (stream end?). Exiting ...") break # Our operations on the frame come here gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY) # Display the resulting frame cv.imshow('frame', gray) if cv.waitKey(1) == ord('q'): break # When everything done, release the capture cap.release() cv.destroyAllWindows()
网页名称:python利用opencv实现保存、播放视频-创新互联
文章分享:http://tyjierui.cn/article/cospdh.html