OpenCV load video from url

前端 未结 2 1837
礼貌的吻别
礼貌的吻别 2020-12-10 13:19

I have a video file (i.e. https://www.example.com/myvideo.mp4) and need to load it with OpenCV.

Doing the equivalent with an image is fairly trivial:

2条回答
  •  一向
    一向 (楼主)
    2020-12-10 14:00

    You will have to read the video using VideoCapture. there is no other way around that for now. unless you define it yourself.

    remember a video is a combination of images changing at defined frame rate.

    So You can read each frame in a while loop. as you apply the imdecode function.

    import numpy as np
    import cv2
    
    cap = cv2.VideoCapture('https://www.example.com/myimage.mp4')
    
    while(cap.isOpened()):
        ret, image = cap.read()    
        loadedImage = cv2.imdecode(image, cv2.IMREAD_COLOR)
        cv2.imshow('frame',loadedImage)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    
    cap.release()
    cv2.destroyAllWindows()
    

提交回复
热议问题