Creating a video using OpenCV 2.4.0 in python

后端 未结 3 1127
悲哀的现实
悲哀的现实 2020-12-05 20:27

I am trying to create a video using OpenCV 2.4.0 in python 2.7.2. But the avi file size is 0.

My code:

from cv         


        
相关标签:
3条回答
  • 2020-12-05 20:35

    Found this code, which works for me (generating colored noise):

    writer = cv2.VideoWriter("output.avi", cv2.VideoWriter_fourcc(*"MJPG"), 30,(640,480))
    for frame in range(1000):
        writer.write(np.random.randint(0, 255, (480,640,3)).astype('uint8'))
    writer.release()
    

    Source: https://github.com/ContinuumIO/anaconda-issues/issues/223#issuecomment-285523938

    0 讨论(0)
  • 2020-12-05 20:47
    height, width, layers = img.shape
    out = cv2.VideoWriter("output.avi", cv2.VideoWriter_fourcc(*"XVID"), 30,(width,height))
    out.write(img)
    out.release()
    
    0 讨论(0)
  • 2020-12-05 20:49
    import cv2
    
    img1 = cv2.imread('1.jpg')
    img2 = cv2.imread('2.jpg')
    img3 = cv2.imread('3.jpg')
    
    height , width , layers =  img1.shape
    
    video = cv2.VideoWriter('video.avi',-1,1,(width,height))
    
    video.write(img1)
    video.write(img2)
    video.write(img3)
    
    cv2.destroyAllWindows()
    video.release()
    

    A simple code for what you want to do. for details here

    0 讨论(0)
提交回复
热议问题