执行图像减法时退出代码139 [英] Exit code 139 when performing image subtraction

查看:51
本文介绍了执行图像减法时退出代码139的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用python执行图像减法.我有numpy数组形式的图像.包含所有图像的列表的大小为1000.列表中的每个numpy数组均为360 * 640类型.当帧数大约为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)

当我执行帧处理为1000的代码时,我得到以下输出:

Process finished with exit code 139

您能帮助我如何克服此错误,并在出现此类错误时提供一些帮助

解决方案

您可能内存不足:您有1000张图片x 360像素x 640像素x 3条带x 8位=大约691 MB ...

代码139在此处列为尝试访问不在地址空间中的虚拟地址",这将支持内存分配错误,如果您使用的RAM数量较少的32位系统,并且其他内容已经在内存中,则很容易发生. /p>

您可以重构代码,这样就不必在内存中保存图像列表,例如,仅将最后一张图像保存在内存中,然后执行减法并用当前图像覆盖它即可.

您可以通过以下方式测试功能:

a = []
for i in range(1000):
    a.append(numpy.ones((360,640,3), dtype=numpy.int))

并查看它是否在不耗尽内存的情况下运行.

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

解决方案

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.

这篇关于执行图像减法时退出代码139的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆