How to read video files using python & Opencv

后端 未结 4 1254
甜味超标
甜味超标 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:31

    The problem is in this line:

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    

    This line expects frame to be a 3 channel or 4 channel Mat object but instead it got some empty Mat and that is why you are getting this assertion failed. You need to check if the frame exists in video and need to handle end of video properly.

    cap.isOpened() will just check if the video file can be opened for reading but it will not return a false when end of video file is reached.

    Try this

提交回复
热议问题