Python-opencv Bug 集合

1、VideoCapture读取本地视频,代码如下:
import numpy as np
import cv2 as cv
cap = cv.VideoCapture('project_video.mp4')
ret = True
while(cap.isOpened()):
    ret, frame = cap.read()
    # gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
#     if ret:
    cv.imshow('frame',frame)
    if cv.waitKey(1) & 0xFF == ord('q'):
        break
cap.release()
cv.destroyAllWindows()
当读取到最后一帧时,出现如下错误:

error: C:\builds\master_PackSlaveAddon-win64-vc12-static\opencv\modules\highgui\src\window.cpp:281: error: (-215) size.width>0 && size.height>0 in function cv::imshow

错误原因:有些摄像头需要一些"warmup",这里对ret做一下判断就行了

参考:

http://answers.opencv.org/question/95889/how-to-solve-this-cvtcolor-error-cv2error-cbuildsmaster_packslaveaddon-win32-vc12-staticopencvmodulesimgprocsrccolorcpp7456-error-215-scn-3-scn-4-in/



猜你喜欢

转载自blog.csdn.net/sinat_31425585/article/details/80278586