cv.VideoCapture遇到的问题记录
1、视频播放不出来
import numpy as np
import cv2 as cv
cap = cv.VideoCapture('opencv\111.mp4')
while(cap.isOpened()):
ret, frame = cap.read()
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
cv.imshow('frame',gray)
if cv.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv.destroyAllWindows()
路径修改为’opencv\111.mp4’,成功
2、
import numpy as np
import cv2 as cv
cap = cv.VideoCapture('opencv\\111.mp4')
while(cap.isOpened()):
ret, frame = cap.read()
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
cv.imshow('frame',gray)
if cv.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv.destroyAllWindows()
视屏可播放,播放到最后一帧出错
发生异常: error
OpenCV(4.1.0) C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'
File "C:\Users\Desktop\opencv4\opencv\2.2.2play video.py", line 18, in <module>
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
修改为
import numpy as np
import cv2 as cv
cap = cv.VideoCapture('opencv\\111.mp4')
while(cap.isOpened()):
ret, frame = cap.read()
if ret:
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
cv.imshow('frame',gray)
if cv.waitKey(25) & 0xFF == ord('q'):
break
else:
break
cap.release()
cv.destroyAllWindows()
正常播放视频
|