我使用 Pytesseract 对屏幕截图运行大量 OCR。这在大多数情况下运行良好,但少数情况会导致此错误:
pytesseract.image_to_string(image,None, False, "-psm 6")
Pytesseract: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 2: character maps to <undefined>
Run Code Online (Sandbox Code Playgroud)
我正在使用Python 3.4。任何如何防止此错误发生的建议(不仅仅是尝试/例外)都会非常有帮助。
我正在尝试在 Jupyter Notebook 上使用 pytesseract。
当我运行以下代码时:
try:
import Image
except ImportError:
from PIL import Image
import pytesseract
pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe'
tessdata_dir_config = '--tessdata-dir "C:\\Program Files (x86)\\Tesseract-OCR\\tessdata"'
print(pytesseract.image_to_string(Image.open('Multi_page24bpp.tif'), lang='en', config = tessdata_dir_config))
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
TesseractError Traceback (most recent call last)
<ipython-input-37-c1dcbc33cde4> in <module>()
11 # tessdata_dir_config = '--tessdata-dir "C:\\Program Files (x86)\\Tesseract-OCR\\tessdata"'
12
---> 13 print(pytesseract.image_to_string(Image.open('Multi_page24bpp.tif'), lang='en'))
14 # print(pytesseract.image_to_string(Image.open('test-european.jpg'), lang='fra'))
C:\Users\cpcho\AppData\Local\Continuum\Anaconda3\lib\site-packages\pytesseract\pytesseract.py in image_to_string(image, lang, boxes, config)
123 if status: …Run Code Online (Sandbox Code Playgroud) 我正在使用 Tesseract 和 Python 从图像构建字符标识符。
\n\n这是我的代码:
\n\nfrom PIL import Image\nimport pytesseract as pyt\n \xc2\xa0\nimage_file = \'location\'\nim = Image.open(image_file)\ntext = pyt.image_to_string(image_file)\nprint (text)\nRun Code Online (Sandbox Code Playgroud)\n\n我在执行该程序时收到以下错误:
\n\n\n\n\n类型错误:不支持的图像对象
\n
有人能解决这个问题吗?
\n
我正在尝试通过图像上的边界框获取选定的文本。就像如果仅通过边界框选择单词一样,我想获取该文本并将其转换为文本文件。请查看我的代码并进行一些审查,以便我可以实现该功能。
到目前为止,我已经将 PDF 文件转换为在文本上带有边框的图像。
import numpy as np
import csv
import io
from PIL import Image
import pytesseract
from wand.image import Image as wi
from pytesseract import Output
import cv2
pdf = wi(filename="samplecompany.pdf", resolution=100)
pdfImg = pdf.convert('jpg')
j = 1
for img in pdfImg.sequence:
page = wi(image=img)
page.save(filename=str(j)+".jpg")
img1 = cv2.imread(str(j)+".jpg")
d = pytesseract.image_to_data(img1, output_type=Output.DICT)
n_boxes = len(d['level'])
print(n_boxes)
for i in range(n_boxes):
(x, y, w, h) = (d['left'][i], d['top']
[i], d['width'][i], d['height'][i])
print((x, y, w, h))
cv2.rectangle(img1, (x, y), …Run Code Online (Sandbox Code Playgroud) 我制作了一个执行 OCR 功能的 Python 脚本,然后回收了该脚本并使用 Flask 制作了一个 Web 应用程序。Web 应用程序及其库位于 virtualenv 中,但该应用程序使用操作系统 (Windows) 中安装的 Tesseract OCR。我一直在本地服务器上对其进行测试。现在是时候进行部署了,我不知道如何在 venv 中安装 Tesseract 或者是否可以将其安装在服务器上。我不知道我说的是否有道理,但我很失落,我将非常感谢任何有关此事的帮助。
先感谢您。
我在 conda 环境中安装了 OCRmyPDF 包,并一直与 pytesseract 一起使用。当我运行命令“ocrmypdf --help”时,我收到以下错误:
[WinError 2] The system cannot find the file specified
Traceback (most recent call last):
File "c:\users\{user}\anaconda3\envs\tesseract\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\users\{user}\anaconda3\envs\tesseract\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\{user}\Anaconda3\envs\tesseract\Scripts\ocrmypdf.exe\__main__.py", line 4, in <module>
File "c:\users\{user}\anaconda3\envs\tesseract\lib\site-packages\ocrmypdf\__init__.py", line 10, in <module>
from ocrmypdf import helpers, hocrtransform, leptonica, pdfa, pdfinfo
File "c:\users\{user}\anaconda3\envs\tesseract\lib\site-packages\ocrmypdf\leptonica.py", line 44, in <module>
raise MissingDependencyError(
ocrmypdf.exceptions.MissingDependencyError:
---------------------------------------------------------------------
This error normally occurs when ocrmypdf can't find the Leptonica …Run Code Online (Sandbox Code Playgroud) 我是 pytesseract 和 OCR 的新手,我在互联网上搜索到这是用于从图像中提取文本的工具。但是,我对此工具一无所知。现在,我遇到了这个错误:tesseract 未安装或不在您的路径中。有关详细信息,请参阅自述文件。
我不知道如何解决这个问题,我尝试了在互联网上找到的各种解决方案,但遗憾的是没有奏效。
错误代码:
TesseractNotFoundError: tesseract is not installed or it's not in your PATH. See README file for more information.
Run Code Online (Sandbox Code Playgroud)
对应代码:
!pip install tesseract
import pytesseract
import cv2
from PIL import Image
import matplotlib.pyplot as plt
img = cv2.imread("meter.jpg")
data = pytesseract.image_to_string(img)
print(data)
# plt.imshow(img)
Run Code Online (Sandbox Code Playgroud)
首先告诉你我正在使用 Jupyterhub。事实上,我在我大学的 jupyterhub 上注册了一个帐户。此外,我在网上搜索了可以使用“cmd”并解决问题的地方。如果是这样,请告诉我该怎么做,否则我必须联系大学管理员来解决这个问题。任何帮助表示赞赏!
我正在尝试在 databrick python 笔记本上运行以下脚本:
pip install presidio-image-redactor
pip install pytesseract
python -m spacy download en_core_web_lg
from PIL import Image
from presidio_image_redactor import ImageRedactorEngine
import pytesseract
image = Image.open("images/ImageData.PNG")
engine = ImageRedactorEngine()
redacted_image = engine.redact(image, (255, 192, 203))
Run Code Online (Sandbox Code Playgroud)
运行最后一行后,我收到以下错误:
TesseractNotFoundError:tesseract 未安装或不在您的路径中。
我错过了什么吗?
我正致力于从图像中提取文本.
最初图像用白色文本着色,在进一步处理图像时,文本显示为黑色,其他像素为白色(带有一些噪声),这里是一个示例:

现在,当我尝试使用pytesseract(tesseract)进行OCR时,我仍然没有得到任何文本.
是否有可能从彩色图像中提取文本?
我已经编写了一个脚本,python用于pytesseract从图像中提取一个单词.该图像中只有一个单词TOOLS,这就是我所追求的.目前我的下面的脚本给了我错误的输出WIS.我该怎么做才能得到文字?
这是我的脚本:
import requests, io, pytesseract
from PIL import Image
response = requests.get('http://facweb.cs.depaul.edu/sgrais/images/Type/Tools.jpg')
img = Image.open(io.BytesIO(response.content))
img = img.resize([100,100], Image.ANTIALIAS)
img = img.convert('L')
img = img.point(lambda x: 0 if x < 170 else 255)
imagetext = pytesseract.image_to_string(img)
print(imagetext)
# img.show()
Run Code Online (Sandbox Code Playgroud)
这是我运行上述脚本时修改后的图像的状态:
我输出的输出:
WIS
Run Code Online (Sandbox Code Playgroud)
预期产量:
TOOLS
Run Code Online (Sandbox Code Playgroud) python web-scraping python-imaging-library python-3.x python-tesseract
python-tesseract ×10
python ×8
tesseract ×7
ocr ×3
python-3.x ×3
databricks ×1
opencv ×1
web-scraping ×1