【发布时间】:2020-04-01 06:05:29
【问题描述】:
我正在尝试将视频保存在特定文件夹中。 但是在运行代码后没有保存输出。 有人可以帮忙吗?谢谢。
cap = cv2.VideoCapture(file_paths[0])
fgbg = cv2.bgsegm.createBackgroundSubtractorMOG()
fourcc = cv2.VideoWriter_fourcc(*'XVID')
name = "C:\jupyter_projects\Test Folder\Intention dataset\background_subtracted\out.mp4"
out = cv2.VideoWriter(name,fourcc, 20,(320,180),False)
while(1):
ret, frame = cap.read()
if (ret == True):
resized_frame = cv2.resize(frame,(320,180),fx=0,fy=0, interpolation = cv2.INTER_CUBIC)
fgmask = fgbg.apply(resized_frame)
cv2.imshow('Frame',fgmask)
out.write(fgmask)
if cv2.waitKey(30) & 0xFF == ord('q'):
break
else:
break
cap.release()
out.release()
cv2.waitKey(5)
cv2.destroyAllWindows()
PS:当我使用默认目录保存视频时,输出将被保存。
out = cv2.VideoWriter("out.mp4",fourcc, 20,(320,180),False)
【问题讨论】:
-
我猜你必须避开路径中的那些空格。例如在 windows 中:"\"C:/Videos/Otters are the cutest/VerySweetOtter.mp4\""
-
@Tollpatsch 我改变了我的路径,但没有再次工作。只有默认路径适用于此
-
你试过使用正斜杠吗?
标签: python python-3.x opencv video video-processing