How to process images of a video, frame by frame, in video streaming using OpenCV and Python

后端 未结 6 863
鱼传尺愫
鱼传尺愫 2020-12-04 10:13

I am a beginner in OpenCV. I want to do some image processing on the frames of a video which is being uploaded to my server. I just want to read the available frames and wri

6条回答
  •  無奈伤痛
    2020-12-04 11:02

    Use this:

    import cv2
    cap = cv2.VideoCapture('path to video file')
    count = 0
    while cap.isOpened():
        ret,frame = cap.read()
        cv2.imshow('window-name', frame)
        cv2.imwrite("frame%d.jpg" % count, frame)
        count = count + 1
        if cv2.waitKey(10) & 0xFF == ord('q'):
            break
    
    cap.release()
    cv2.destroyAllWindows() # destroy all opened windows
    

提交回复
热议问题