我正在使用 tesseract 进行 OCR。我在 ubuntu 18.04 上。
我有这个程序可以从图像中提取文本并打印出来。我希望该程序创建一个新的文本文件并将提取的内容粘贴到新的文本文件中,但我只能执行这些操作
这是我从图像中提取文本的程序
from pytesseract import image_to_string
from PIL import Image
print image_to_string(Image.open('sample.jpg'))
这是将文本复制到剪贴板的程序,
import os
def addToClipBoard(text):
command = 'echo ' + text.strip() + '| clip'
os.system(command)
该程序将打开 geditor 并创建一个新的文本文件
import subprocess
proc = subprocess.Popen(['gedit', 'file.txt'])
任何帮助,将不胜感激。
如果您只想要文本,请打开一个文本文件并写入其中:
from pytesseract import image_to_string
from PIL import Image
text = image_to_string(Image.open('sample.jpg'))
with open('file.txt', mode = 'w') as f:
f.write(text)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句