0
我試圖在視頻上應用Canny過濾器,以便在output.mp4文件中使用canny過濾器生成視頻。 我發現輸出文件大小1kilobyte雖然原始視頻大小爲30兆字節無法將視頻保存在opencv 3中
這是我使用的代碼:
import numpy as np
import cv2
Video = cv2.VideoCapture('video.mp4')
width = int(Video.get(cv2.CAP_PROP_FRAME_WIDTH) + 0.5)
height = int(Video.get(cv2.CAP_PROP_FRAME_HEIGHT) + 0.5)
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
out = cv2.VideoWriter('output.mp4', fourcc, 20.0, (width, height))
while(Video.isOpened()):
ret, frame = Video.read()
if ret==True:
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray, 100, 100)
cv2.imshow('frame',edges)
out.write(edges)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
Video.release()
out.release()
cv2.destroyAllWindows()
您是否安裝了編解碼器? –
是的。我在Windows上使用Spyder在Anconda 3上運行此代碼 –
嘗試安裝'XVID'編解碼器並以.avi格式保存文件 –