将一个视频沿垂直轴翻转保存
import cv2 as cv
cap = cv.VideoCapture("picture\seven_sin.mp4")
fourcc = cv.VideoWriter_fourcc(*'XVID')
out = cv.VideoWriter('output.avi', fourcc, 23.98, (1920, 1080))
while cap.isOpened():
ret, frame = cap.read()
if not ret:
print("Can`t receive frame (stream end?). Exiting...")
break
frame = cv.flip(frame, 0)
# frame = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
out.write(frame)
cv.imshow('frame', frame)
if cv.waitKey(1) == ord('q'):
break
cap.release()
out.release()
cv.destroyAllWindows()
视频处理对象为框架frame,图片处理对象是图片image
不知道为什么保存为灰度时就不行,只有垂直翻转能正常写入…
还有需要注意的就是,VideoWriter对象的size跟写入的size要是一样的,不然也会出现写不进去的情况