Python Forum
opencv memory question - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: opencv memory question (/thread-17573.html)



opencv memory question - djf123 - Apr-16-2019

Basically I want to convert a .mts movie file to a numpy array. Each frame of the movie is 1080x1920 and the file is 47.1 MB in size for 721 frames. What I want is to convert this to a numpy array of size (721,1080,1920,3). For some reason my attempt to do so is giving the error
Error:
Traceback (most recent call last): File "<pyshell>", line 13, in <module> cv2.error: OpenCV(3.4.4) C:\projects\opencv-python\opencv\modules\core\src\alloc.cpp: 55: error: (-4:Insufficient memory) Failed to allocate 6220800 bytes in function 'cv::OutOfMemoryError'
I'm not sure why this is happening as I am using a computer with 63.9 GB of usable RAM with no other programs open in Windows 10 using the Thonny IDE. Why is this happening, and how do I fix this?

Below is my code:
import cv2
import numpy as np

vidcap=cv2.VideoCapture('C:\\Users\\John\\Desktop\\delete\\00001.mts')
success, image=vidcap.read()
g=[]
g.append(image)
length=int(vidcap.get(cv2.CAP_PROP_FRAME_COUNT))
count=2
while success:
    if count<length:
        vidcap.set(cv2.CAP_PROP_POS_FRAMES,count)
        sucess, image =vidcap.read()
        count=count+1
        g.append(image)
    else:
        success=False

R=np.asarray(g)
        
        
        



RE: opencv memory question - heiner55 - May-26-2019

So 721 * 1080 * 1920* 3 = 4.5 GByte

Are you using 32bit or 64bit Python ?