On windows 10, python 2.7.11, recent opencv 3 build with cmake
Here is a simple example of trying to create a background model from pictures, not video. This only occurs when using pictures from file, not when using cv2.videocapture from a video file to read frames. It fails on the very first position in the loop. Once they are numpy arrays, what does it matter?
Looking at memory, it does rise, but certainly does not spike dramatically.
I've tried smaller photos (shape~ (1920,2560,3) and i get the error after 3 photos.
import cv2
import glob
import os
import cv2.bgsegm
#File formats
ext="C:/Users/Ben/Desktop/pics2/*.jpg"
#Create mog
b=cv2.createBackgroundSubtractorMOG2()
#Find photos
jpgs=[]
jpgs.extend(glob.glob(ext))
#Read in photos and add to background
for x in jpgs:
current_image=cv2.imread(x)
print("Photo size is %s" % str(current_image.shape))
b.apply(current_image)
Returns:
Photo size is (2992, 5152, 3)
OpenCV Error: Insufficient memory (Failed to allocate 1541478400 bytes) in OutOfMemoryError, file C:\opencv\source\opencv\modules\core\src\alloc.cpp, line 52
OpenCV Error: Assertion failed (u != 0) in create, file C:\opencv\source\opencv\modules\core\src\matrix.cpp, line 432
It may be related to this, but its not obvious there is a python solution. https://github.com/Itseez/opencv/issues/4871