1. 程式人生 > >python opencv cv2 to process video

python opencv cv2 to process video

本文總結下使用cv2做視訊處理的一些基本步驟。

#讀入視訊
import cv2
videocap = cv2.VideoCapture("/cv/Desktop/1.avi")
#儲存視訊圖片
fourcc = cv2.cv.CV_FOURCC(*XVID)
video_FPS = 25
framesize = (image.shape[1],image.shape[0])
video_name = "/cv/Desktop/hello.avi"
newvideo = cv2.VideoWriter(video_name,fourcc,video_FPS,framesize)
#it is only a handle of a video,you need to save image frame into it ,a lot of image
newvideo.write(image) #after save all image,you need to release the video newvideo.release() #顯示視訊 cv2.imshow("window_name",image) cv2.waitKey(10) #get another image to show res,image = videocap.read()