How to read video files using python & Opencv

后端 未结 4 1253
甜味超标
甜味超标 2020-12-31 19:50

I am reading an avi file usinh python 2.7 and opencv2.4.I am using windows 10.My sample code is

import numpy as np
import cv2
cap = cv2.VideoCapture(\'videos         


        
4条回答
  •  我在风中等你
    2020-12-31 20:32

    Well I am guessing the capture is not open. That's why your program ends instantly when you use while(cap.isOpened()):.

    As stated in this doc it happens that the capture is not implicitly opened when created.

    Sometimes, cap may not have initialized the capture. In that case, this code shows error. You can check whether it is initialized or not by the method cap.isOpened(). If it is True, OK. Otherwise open it using cap.open().

    Try to explicitly open the capture like so :

    cap = cv2.VideoCapture('videos/wa.avi')
    cap.open();
    while(cap.isOpened()):
    ...
    

    If this does not work you will have to check for the video file path.

提交回复
热议问题