Why is OpenCV retrivieng this error in the middle of a video processing? error: (-215) scn == 3 || scn == 4 in function cv::cvtColor

Why is OpenCV retrivieng this error in the middle of a video processing? error: (-215) scn == 3 || scn == 4 in function cv::cvtColor

我正在使用 openCV 处理 python2

的视频捕获(.mkv 文件)
import cv2
(....)

videofile = 'a.mkv'
cap = cv2.VideoCapture(videofile)
(....)
t_frames, fps, t_time, w, h = getVideoInfo(cap)
(....)
cap.set(cv2.CAP_PROP_POS_FRAMES ,first_frame)
(....)
frame = 0
while (not stopped==1):
    ret, frame = cap.read(frame)
    (...some functions related with cv2 are here called...)
    frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    (...)

然而,在视频处理接近尾声时出现了一些错误: 错误:(-215)scn == 3 ||函数中的 scn == 4 cv::cvtColor

并且错误发生在cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) 任何想法?框架不好?但是我之前调用了一些与cv2相关的函数,没问题。

加载资源后检查资源是否正确加载。

ret, frame = cap.read(frame)
(....)
if frame is not None
    frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)