遇到有关 Pytesseract 的以下代码的此错误代码的问题。(Python 3.6.1,Mac OSX)
从 PIL 导入 pytesseract 导入请求 从 PIL 导入图像 从 io 导入 ImageFilter 导入 StringIO, BytesIO
def process_image(url):
image = _get_image(url)
image.filter(ImageFilter.SHARPEN)
return pytesseract.image_to_string(image)
def _get_image(url):
r = requests.get(url)
s = BytesIO(r.content)
img = Image.open(s)
return img
process_image("https://www.prepressure.com/images/fonts_sample_ocra_medium.png")
Run Code Online (Sandbox Code Playgroud)
错误:
/usr/local/Cellar/python3/3.6.0_1/Frameworks/Python.framework/Versions/3.6/bin/python3.6 /Users/g/pyfo/reddit/ocr.py
Traceback (most recent call last):
File "/Users/g/pyfo/reddit/ocr.py", line 20, in <module>
process_image("https://www.prepressure.com/images/fonts_sample_ocra_medium.png")
File "/Users/g/pyfo/reddit/ocr.py", line 10, in process_image
image.filter(ImageFilter.SHARPEN)
File "/usr/local/lib/python3.6/site-packages/PIL/Image.py", line 1094, in filter
return self._new(filter.filter(self.im))
File "/usr/local/lib/python3.6/site-packages/PIL/ImageFilter.py", line 53, in filter
raise ValueError("cannot …Run Code Online (Sandbox Code Playgroud) 我目前正在从事一个涉及使用 Tess4j Tesseract OCR 引擎的项目。在从事这个项目时,我遇到了很多网站,这些网站声称 Tesseract 在至少 300 DPI(每英寸点数)的图像上效果最好。
我的问题是为什么在图像中多次提到 DPI。我知道当您扫描一个对象时,您希望以至少 300 DPI 对其进行扫描。我只是不明白为什么这与用相机拍摄的照片有关。据我所知,DPI 是打印机的一个属性。基于此属性,它越高,图像越小,但质量越高。
现在,如果 DPI 与这些图像无关,那么我想知道为什么当我在 72 和 300 之间更改图像的 DPI 属性时,程序的结果会有所不同。是否有我不知道的 Tesseract 预处理?
在 OCR 上工作。我可以导入 asprise_ocr_api 并且我想解决这个问题:
from asprise_ocr_api import *
Ocr.set_up()
ocrEngine = Ocr()
ocrEngine.start_engine("eng")
s = ocrEngine.recognize("1.png", -1, -1, -1, -1, -1,
OCR_RECOGNIZE_TYPE_ALL, OCR_OUTPUT_FORMAT_PLAINTEXT)
print("Result: " + s)
ocrEngine.stop_engine()
Run Code Online (Sandbox Code Playgroud)
因为代码失败:
输出:
File "C:\Users\hp\PycharmProjects\KOFAI(Knight Online Arfiitical ^
Intelligince\MNIST.py", line 1, in <module>
from asprise_ocr_api import *
File "C:\Users\hp\AppData\Local\Programs\Python\Python36\lib\site-
packages\asprise_ocr_api\__init__.py", line 1, in <module>
from ocr import *
ModuleNotFoundError: No module named 'ocr'
Run Code Online (Sandbox Code Playgroud)
我不断收到此错误。我需要帮助 :)
我正在构建一个 Android 应用程序,其中需要从图片中识别七段数字并在处理数据后填充屏幕。
这需要在离线模式下发生。所以它需要在移动设备上运行
我看过 Tess,但它使应用程序的大小相当大,因此我想在 Firebase 上坚持使用 ML Kit。
有没有办法在现有的 ML Kit 文本视觉 API 中添加七段数字识别?
我已经扫描了银行对账单的 PDF(基于图像)。谷歌视觉 API 能够非常准确地检测文本,但它返回文本块,我需要逐行文本(银行交易)。知道如何去做吗?
我正在尝试使用pytesseract模块读取验证码。它大部分时间都提供准确的文本,但并非总是如此。
这是读取图像、操作图像和从图像中提取文本的代码。
import cv2
import numpy as np
import pytesseract
def read_captcha():
# opencv loads the image in BGR, convert it to RGB
img = cv2.cvtColor(cv2.imread('captcha.png'), cv2.COLOR_BGR2RGB)
lower_white = np.array([200, 200, 200], dtype=np.uint8)
upper_white = np.array([255, 255, 255], dtype=np.uint8)
mask = cv2.inRange(img, lower_white, upper_white) # could also use threshold
mask = cv2.morphologyEx(mask, cv2.MORPH_OPEN, cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3))) # "erase" the small white points in the resulting mask
mask = cv2.bitwise_not(mask) # invert mask
# load background (could be an …Run Code Online (Sandbox Code Playgroud) 通过tesseract-OCR,我试图从以下带有红色背景的图像中提取文本。
我在提取框 B 和 D 中的文本时遇到问题,因为有垂直线。我怎样才能像这样清理背景:
输入:
输出:
我正在努力使用 Tesseract OCR。我有一张血液检查图像,它有一张带压痕的表格。尽管 tesseract 能够很好地识别字符,但其结构并未保留在最终输出中。例如,查看“Emocromo con formula”(英文翻译:带有公式的血细胞计数)下面的缩进行。我想保留那个缩进。
我阅读了其他相关讨论并找到了选项preserve_interword_spaces=1。结果稍微好一点,但正如您所看到的,它并不完美。
有什么建议?
更新:
我尝试了 Tesseract v5.0,结果是一样的。
代码:
Tesseract 版本是 4.0.0.20190314
from PIL import Image
import pytesseract
# Preserve interword spaces is set to 1, oem = 1 is LSTM,
# PSM = 1 is Automatic page segmentation with OSD - Orientation and script detection
custom_config = r'-c preserve_interword_spaces=1 --oem 1 --psm 1 -l eng+ita'
# default_config = r'-c -l eng+ita'
extracted_text = pytesseract.image_to_string(Image.open('referto-1.jpg'), config=custom_config)
print(extracted_text)
# saving to a txt …Run Code Online (Sandbox Code Playgroud) 我正在研究一个项目使用计算机视觉从发票中提取数据,我正在尝试使用 opencv 和 pytesseract 从图像发票中提取数据,并进一步Regex将原始数据分离到不同的部分,如日期、供应商名称、发票编号,项目名称和项目数量。开始时我试图提取日期但遇到错误。
这是我的代码
import pytesseract
from pytesseract import Output
import cv2
img = cv2.imread('invoice.png')
d = pytesseract.image_to_data(img, output_type=Output.DICT)
n_boxes = len(d['level'])
for i in range(n_boxes):
(x, y, w, h) = (d['left'][i], d['top'][i], d['width'][i], d['height'][i])
img = cv2.rectangle(img, (x, y), (x + w, y + h), (0, 0, 255), 2)
cv2.imshow(img,'img')
Run Code Online (Sandbox Code Playgroud)
但我收到这个错误
File "testpdf3.py", line 12, in <module>
cv2.imshow(img,'img')
SystemError: <built-in function imshow> returned NULL without setting an error
Run Code Online (Sandbox Code Playgroud) 我正在尝试从图像中提取手写数字和字母表,为此我遵循了这个 stackoverflow 链接。对于大多数使用标记写入字母的图像来说,它工作正常,但是当我使用使用 Pen 写入数据的图像时,它却失败了。需要一些帮助来解决这个问题。
下面是我的代码:
import cv2
import imutils
from imutils import contours
# Load image, grayscale, Otsu's threshold
image = cv2.imread('xxx/pic_crop_7.png')
image = imutils.resize(image, width=350)
img=image.copy()
# Remove border
kernel_vertical = cv2.getStructuringElement(cv2.MORPH_RECT, (1,50))
temp1 = 255 - cv2.morphologyEx(image, cv2.MORPH_CLOSE, kernel_vertical)
horizontal_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (50,1))
temp2 = 255 - cv2.morphologyEx(image, cv2.MORPH_CLOSE, horizontal_kernel)
temp3 = cv2.add(temp1, temp2)
result = cv2.add(temp3, image)
# Convert to grayscale and Otsu's threshold
gray = cv2.cvtColor(result, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray,(5,5),0)
_,thresh = cv2.threshold(gray, 0, 255, …Run Code Online (Sandbox Code Playgroud)