Hi everyone,
I tried execute cv2.VideoWriter and save frame per frame after use Background Subtraction with MOG, however, when tried open the final video, not executed.
below, the code:
cap = cv2.VideoCapture('images/RodoviaCoreia.mp4')
# Get the height and width of the frame (required to be an interger)
w = int(cap.get(3))
h = int(cap.get(4))
# Definindo o CODEC e o video de saida
out = cv2.VideoWriter('Rodovia-Coreia-MOG.mp4', cv2.VideoWriter.fourcc('M','P','4','V'), 30, (w, h))
# Aplicando o MIXTURE OF GAUSSIANS
foreground_background = cv2.bgsegm.createBackgroundSubtractorMOG()
# aplicando para cada frame
while True:
ret, frame = cap.read()
if ret:
# Apply background subtractor to get our foreground mask
foreground_mask = foreground_background.apply(frame)
imshow("Foreground Mask", foreground_mask)
out.write(foreground_mask)
else:
break
cap.release()
out.release()