Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exit code 139 when performing image subtraction

Tags:

python

numpy

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

like image 699
user3646052 Avatar asked May 16 '14 20:05

user3646052


People also ask

How do I fix exit code 139?

This is a very common mistake and can be fixed by simply updating the version number whenever you update a library and its binaries.

What is exit code 139 in Python?

This indicates a bug in your program. In a Python program, this is either a bug in the interpreter or in an extension module being used (and the latter is the most common cause).

Did not complete successfully exit code 139?

Exit Code 139 means that the container received a SIGSEGV signal from the operating system. This indicates a segmentation error – a memory violation, caused by a container trying to access a memory location to which it does not have access.


2 Answers

I had a similar problem with opencv-python==3.1.0. I was having:

Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

error all of a sudden after many successful calls of cv2.seamlessClone.

For me, the solution was to upgrade to opencv-python==3.4.10.37

like image 93
Barış Geçer Avatar answered Oct 06 '22 23:10

Barış Geçer


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.

like image 44
Benjamin Avatar answered Oct 06 '22 23:10

Benjamin