Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
opencv memory question
#1
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)
        
        
        
Reply
#2
So 721 * 1080 * 1920* 3 = 4.5 GByte

Are you using 32bit or 64bit Python ?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Newbie.... run for cover. OpenCV question Stevolution2023 2 921 Apr-12-2023, 12:57 PM
Last Post: Stevolution2023
  quick question about deleting an object from memory LavaCreeperKing 5 5,769 Nov-12-2016, 04:05 PM
Last Post: LavaCreeperKing

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020