import numpy as np
import cv2 as cv
cap = cv.VideoCapture('vtest.avi')
while(cap.isOpened()):
# Capture frame-by-frame
ret, frame = cap.read()
# Our operations on the frame come here
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
# Display the resulting frame
cv.imshow('frame',gray)
if cv.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv.destroyAllWindows()
github 上的 vtest.avi 無法使用,所以以下將改用此處的 drop.avi。
當程式讀到檔案的最後,執行 gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY) 會出現錯誤
error: ..\..\..\modules\imgproc\src\color.cpp:7456: error: (-215) scn == 3 || scn == 4 in function cv::ipp_cvtColor看了 stackoverflow 上的說明,還是不行。只好找出 cv.VideoCapture 中,read() 的說明和使用。


