我有以下代码,它使用Tesseract-OCR(python wrapper- tesserocr)从包含文本的图像中提取字体属性。
for image in image_list:
print "Starting for ",image
font_attribute_list = []
with PyTessBaseAPI(oem=0) as api:
image1 = PIL.Image.open(path+image)
api.SetImage(image1)
api.Recognize()
iterator = api.GetIterator()
font_attribute_list.append(iterator.WordFontAttributes())
word_font_attribute_dataframe = word_font_attribute_dataframe.append([font_attribute_list[0]], ignore_index=True)
image1.close()
这仅适用于少量图像,并且该数字会不断变化。有时它运行大约13-14个图像,有时大约100,然后停止。没有错误或任何事情。它结束了。有时它会给出错误“Segmentation fault(core dumped)”。我正在使用Ubuntu 14.04。
我该如何解决这个问题?
一切听起来都很有趣。通常情况下,当您遇到分段错误时,这意味着您正在尝试同时执行太多操作并且它会堵塞您的记忆。您的代码可能不仅仅是在没有错误的情况下停止,它可能仍然存在,只是非常慢。
看起来你在该循环的每次迭代中打开一个图像,所以可能所有打开的图像都耗尽了你的工作记忆。您可以尝试在循环结束前关闭图像。