video: bytes written in file are different from those read

1

I am new with opencv and I have a question. I explain it using the following example:

import cv2
import numpy as np

def LoadVideo(fileName):
    # Create a VideoCapture object and read from input file
    # If the input is taken from the camera, pass 0 instead of the video file name.
    cap = cv2.VideoCapture(fileName)
    while(cap.isOpened()):
        # Capture frame-by-frame
        ret, frame = cap.read()        
        if ret == True:        
            # Display the resulting frame
            cv2.imshow('Frame',frame)
            frame2 = np.array(frame)
                    # Press Q on keyboard to  exit
            if cv2.waitKey(25) & 0xFF == ord('q'):
                break        
        # Break the loop
        else: 
            break

    # When everything done, release the video capture object
    cap.release()

    # Closes all the frames
    cv2.destroyAllWindows()

def WriteVideo(fileName):
    encoding = cv2.VideoWriter_fourcc('I','4','2','0')
    #encoding = cv2.VideoWriter_fourcc('8','B','P','S')
    video = cv2.VideoWriter(fileName, encoding, 2, (300,300))
    video = cv2.VideoWriter(fileName, 0, 2, (300,300))
    ret = video.set(cv2.CAP_PROP_CONVERT_RGB,1)
    nFrames = 30
    for i in range(nFrames):
        frame = np.multiply(np.ones((300,300,3),dtype=np.uint8),i)
        video.write(frame)
    video.release()

if __name__ == "__main__":
    WriteVideo('hola.avi')
    LoadVideo('hola.avi')

The program simply writes images using 300x300x3 matrices that in the first frame are all values 0, in the second they are all 1, etc.

What I expected is that reading (and decoding) the video with read is finding the same matrices, but it turns out that they are not the ones I wrote (they are encoded in some way).

The question is if there is a way to retrieve the original information.

    
asked by Francisco 10.05.2018 в 10:51
source

0 answers