Python播放视频

通过OpenCV,制作一个简单的视频播放工具,代码如下,

import numpy as np
import cv2 as cv
cap = cv.VideoCapture('temp.avi')
while cap.isOpened():
    ret, frame = cap.read()
    # if frame is read correctly ret is True
    if not ret:
        print("Can't receive frame (stream end?). Exiting ...")
        break
    # show gray picture
    #gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
    #cv.imshow('frame', gray)
    cv.imshow('frame', frame)
    if cv.waitKey(1) == ord('q'):
        break
cap.release()
cv.destroyAllWindows()

关于更详细的内容,请参考OpenCV官方文档,
https://docs.opencv.org/master/dd/d43/tutorial_py_video_display.html

你可能感兴趣的:(video,video)