Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
提取表格图像数据并使用python将其保存为CSV格式_Python - Fatal编程技术网

提取表格图像数据并使用python将其保存为CSV格式

提取表格图像数据并使用python将其保存为CSV格式,python,Python,获取图像格式的表格数据(参见图1) 表格数据需要提取并以CSV格式保存(与表格相同) 我用pytesseract从图像中读取数据,部分工作正常 代码: 输出: 输出文件以文本格式打开,我无法获得完美的csv格式(如图中的表格) 任何帮助都将不胜感激。TIA这是数据挖掘领域中一个众所周知但尚未普遍解决的问题,称为表检测。我猜肯定不会有现成的解决方案。哦……好的。当我试图将其直接保存为csv文件时,数据被填充为'R'、'E'、'P'、'O'…每个单元格都有每个字符。我面临着同样的问题,有解决方案

获取图像格式的表格数据(参见图1)

表格数据需要提取并以CSV格式保存(与表格相同)

我用pytesseract从图像中读取数据,部分工作正常 代码:

输出:

输出文件以文本格式打开,我无法获得完美的csv格式(如图中的表格)


任何帮助都将不胜感激。TIA

这是数据挖掘领域中一个众所周知但尚未普遍解决的问题,称为表检测。我猜肯定不会有现成的解决方案。哦……好的。当我试图将其直接保存为csv文件时,数据被填充为'R'、'E'、'P'、'O'…每个单元格都有每个字符。我面临着同样的问题,有解决方案吗?
from PIL import Image
from ast import literal_eval
import pytesseract,csv,re,os
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files (x86)\Tesseract-OCR\tesseract.exe'

result = pytesseract.image_to_string(Image.open(r'D:\Sample.jpg'),lang="eng")

#print(type(result))
print(result)

with open('D:\people.csv', 'w') as outfile:
    writer = csv.writer(outfile)
    #writer.replace(",", "")
    writer.writerow(result)

string = open('D:\people.csv').read()
new_str = re.sub('[^a-zA-Z0-9\n\.]', ' ', string)
open('D:\people.csv', 'w').write(new_str)