【发布时间】:2015-06-28 00:39:11
【问题描述】:
我有一个远程 PDF 文件,我需要逐页阅读并不断将每个文件传递给 OCR,它会为我提供 OCR 文本。
import pytesseract
from pyPdf import PdfFileWriter, PdfFileReader
import cStringIO
from wand.image import Image
import urllib2
import tempfile
import pytesseract
from PIL import Image
remoteFile = urllib2.urlopen(urllib2.Request("file:///home/user/Documents/TestDocs/test.pdf")).read()
memoryFile = cStringIO.StringIO(remoteFile)
pdfFile = PdfFileReader(memoryFile)
for pageNum in xrange(pdfFile.getNumPages()):
currentPage = pdfFile.getPage(pageNum)
## somehow convert currentPage to wand type
## image and then pass to tesseract-api
##
## TEMP_IMAGE = some conversion to temp file
## pytesseract.image_to_string(Image.open(TEMP_IMAGE))
memoryFile.close()
我曾想过使用cStringIO 或tempfile,但我不知道如何将它们用于此目的。
如何解决这个问题?
【问题讨论】:
标签: python pdf wand python-tesseract