【问题标题】:Exit code 139 when performing image subtraction执行图像减法时退出代码 139
【发布时间】:2014-05-16 20:28:37
【问题描述】:

我正在使用 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

您能否帮助我如何克服此错误并在我遇到此类错误时提出一些建议

【问题讨论】:

  • 在这段代码中,我只是减去和存储图像。我没有进行任何无效的内存访问。我是这个 python 编码的新手。你能帮我克服这个错误吗
  • 不幸的是,没有简单的方法可以解决这个问题,首先尝试将 Python 和 OpenCV 更新到最新版本,如果这没有帮助,您需要使用 gdb 等调试器。
  • 感谢您的回复。我已经从 python2.7 升级到了 python3。但是我找不到将 Opencv 配置为 python3 的过程,因为我的 ubuntu 操作系统中已经有 python2.7。你能建议我做一个程序吗
  • OpenCV 与 Python 3 不兼容。

标签: python numpy


【解决方案1】:

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

代码 139 被列为 here 为“尝试访问不在您的地址空间中的虚拟地址”,这将支持内存分配错误,如果您在 32 位系统上使用少量内存,则很容易发生这种情况RAM,其他东西已经在内存中。

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

您可以通过将函数替换为:

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

看看它是否在没有耗尽内存的情况下运行。

【讨论】:

  • python虚拟机内存不足时不会出现单独的MemoryError异常吗?
【解决方案2】:

opencv-python==3.1.0 也有类似的问题。我有:

进程以退出代码 139 结束(被信号 11:SIGSEGV 中断)

多次成功调用 cv2.seamlessClone 后突然出错。

对我来说,解决方案是升级到 opencv-python==3.4.10.37

【讨论】:

    猜你喜欢
    • 2021-03-07
    • 2021-04-02
    • 2022-07-05
    • 2019-08-25
    • 1970-01-01
    • 2017-01-20
    • 2017-11-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多