python opencv的视频与图像操作

python opencv的视频与图像操作

0.载入模型

import cv2 as cv

1.载入视频

VideoCaptrue=cv.VideoCapture()
#get the fps and size
fps = VideoCapture.get(CV_CAP_PROP_FPS )
size = (int(VideoCapture.get(CV_CAP_PROP_FRAME_WIDTH)),
      int(VideoCapture.get(CV_CAP_PROP_FRAME_HEIGHT)))

2.将视频每一帧转化为图片

while(VideoCapture.isOpened()):
    ret, frame = VideoCapture.read()# frame为每帧图片

3.处理了

blur = cv2.medianBlur(frame,5)# 中值滤波

4.将处理后的图片转化为图片

cap = cv2.VideoCapture('output.avi')

while(cap.isOpened()):
    ret, frame = cap.read()
    if ret == True:
        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        cv2.imshow('image', gray)
        k = cv2.waitKey(20)
        if (k & 0xff == ord('q')):
            break
    else:
        break

cap.release()
cv2.destroyAllWindows()

你可能感兴趣的:(opencv,python)