我正在尝试将视频转换为灰度,但无法正常工作。这是我使用的代码。
import cv2
capture = cv2.VideoCapture("C:/Users/firas/Desktop/ASU/Research Wu_/v3/experiment_no graphs.mp4")
fourcc = cv2.VideoWriter_fourcc(*'MJPG')
out = cv2.VideoWriter('BW.avi', fourcc, 5, (128,72))
while(True):
ret, frame = capture.read()
grayFrame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('video gray', grayFrame)
cv2.imshow('video original', frame)
out.write(grayFrame)
if cv2.waitKey(1) == ord('q'):
break
out.release()
capture.release()
cv2.destroyAllWindows()