【Python】-004 OpenCV-Python读取并显示视频

【Python】-004 OpenCV-Python读取并显示视频

  OpenCV提供了python绑定,能够很方便的进行图像处理。

1、OpenCV-Python读取视频

  

import numpy as np
import cv2 as cv
# open the video file
cap = cv.VideoCapture('you path to the video file!');

while(1):
    # take a frame from the video file
    ret ,frame = cap.read();
    # if read not success, break the loop and exit
    if ret != True:
        break;
    # show the frame read from the video
    cv.imshow('video',frame);
    # wait a time, if not, the window will always gray!
    cv.waitKey(60);
# close all windows opened by opencv
cv.destroyAllWindows();
# release the video file
cap.release();

2、注意

  在循环内部使用imshow显示图像,由于循环的作用,如果不加waitkey,将导致窗口显示的图像始终是灰色!

猜你喜欢

转载自blog.csdn.net/freehawkzk/article/details/82013510