Exit code 139 when performing image subtraction
numpy, python
Solution
You might be running out of memory: you have 1000 images x 360 pixels x 640 pixels x 3 bands x 8 bits = about 691 MB...
Code 139 is listed here as "attempt to access a virtual address which is not in your address space", which would support a memory allocation error, which could happen easily if you are on 32-bit system with low amount of RAM, and other things are already in memory.
You might refactor your code so that it's not necessary to hold a list of images in memory, for instance, only hold the last image in memory, then perform the subtraction and overwrite it with the current image.
You could test this by replacing your function with:
a = []
for i in range(1000):
a.append(numpy.ones((360,640,3), dtype=numpy.int))
and seeing if that runs without running out of memory.
Problem
I am performing an image subtraction using python. I have images in the form of numpy arrays. The size of the list that carrying all images is 1000. Each numpy array in the list is of 360*640 type. The frame subtraction is happening correct when the number of frames is around 300. ``` def find_der(frames): der = [] for a in range(len(frames)-1): der.append(frames[a + 1] - frames[a]) return der framesprocessing = 1000 for j in range(framesprocessing): img = cv.QueryFrame(video) if img is None: print("Images are Not Captured") else: tmp = cv.CreateImage(cv.GetSize(img), 8, 3) saveImagesColor = 'Abhiram_images/RGB/frame' + str(i) + '.png' #Saving the iplimages to the local PC cv.SaveImage(saveImagesColor, img) saveImagesGray = 'Abhiram_images/GRAY/frame' + str(i) + '.png' #Saving the grayscale images to the local PC img1 = cv2.imread(saveImagesColor) grayimg = cv2.cvtColor(img1,cv2.COLOR_BGR2GRAY) cv2.imwrite(saveImagesGray, grayimg) graynumpyimage = np.array(grayimg, dtype='int64') grayscale.append(graynumpyimage) i += 1 first_der = find_der(grayscale) ``` When I execute the code with frames processing as 1000 I am getting the following output: ``` Process finished with exit code 139 ``` Could you help me how to overcome this error and throw some light when I will get such a kind of error