- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试从 tif 或 tiff 图像文件中读取文本。这些文件有多个页面。
当我打印数组时,我只得到 true,然后没有文本。但是,当我使用 .png 文件时,我能够打印文本。
下面是我的代码。
from PIL import Image, ImageSequence
import pytesseract
from pytesseract import image_to_string
import numpy as np
import cv2
test = Image.open(r'C:\Python\BG36820V1.tiff')
#test1 = Image.open(r'C:\Users\Documents\declaration.png')
testarray = np.array(test)
print(testarray)
print(pytesseract.image_to_string(Image.fromarray(testarray))
这是测试文件的输出:
[[ True True True ... True True True]
[ True True True ... True True True]
[ True True True ... True True True]
...
[ True True True ... True True True]
[ True True True ... True True True]
[ True True True ... True True True]]
但是这对 test1 工作正常。
[[[242 242 242 255]
[242 242 242 255]
[242 242 242 255]
...
[242 242 242 255]
[242 242 242 255]
[242 242 242 255]]
[[182 180 182 255]
[182 180 182 255]
[182 180 182 255]
...
[182 180 182 255]
[182 180 182 255]
[182 180 182 255]]
g Request 4042337300021 submitted sucessfully
x
TYPE
我尝试用 opencv 读取 tiff 文件,但格式不受支持。
如何打印 tiff 或 tif 文件中的文本。
有什么建议吗?
问候,任.
最佳答案
修改了我的整个代码并将 tiff 文件转换为 jpeg 文件,它能够读取文本。
from PIL import Image, ImageSequence
import pytesseract
from pytesseract import image_to_string
import numpy as np
import cv2
import os
yourpath = r'C:\Python\'
for root, dirs, files in os.walk(yourpath, topdown=False):
for name in files:
print(os.path.join(root, name))
if os.path.splitext(os.path.join(root, name))[1].lower() == ".tiff":
if os.path.isfile(os.path.splitext(os.path.join(root, name))[0] + ".jpg"):
print ("A jpeg file already exists for %s" % name)
# If a jpeg is *NOT* present, create one from the tiff.
else:
outfile = os.path.splitext(os.path.join(root, name))[0] + ".jpg"
try:
im = Image.open(os.path.join(root, name))
print ("Generating jpeg for %s" % name)
im.thumbnail(im.size)
im.save(outfile, "JPEG", quality=100)
except Exception as e:
print (e)
test = Image.open(r'C:\Python\BG96254V1.jpeg')
testarray = np.array(test)
print(testarray)
print(pytesseract.image_to_string(Image.fromarray(testarray)))
这只阅读第一页而不是页面列表。关于如何进行更改以阅读所有页面的任何建议。
谢谢。
关于python-3.x - Image_to_string 不使用 pytesseract 从 tiff 或 tif 文件中读取文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52430601/
我在 Windows 10 机器上使用 python3.7 和 Tesseract-OCR 版本 5。我有包含数字的图片。然而,尽管人眼非常清楚,但 Tesseract 无法正确提取它们。有些人给了我
这里的问题是我需要删除行并编写代码来识别字符。到目前为止,我已经看到了解决方案,其中 char 是实心的,但它有带双边框的 char。 最佳答案 对于这个特定的验证码,有一个非常简单的解决方案。但是,
我在图像中有一个简单的文本 image_ball.png .通常 Tesseract 的 OCR 效果很好,但是对于这个特定的图像,它总是返回一个空字符串。 In [1]: from PIL impo
我正在尝试在 Mac Maverick 中遵循这个 pytesser ( link) 的例子。 >>> from pytesser import * >>> im = Image.open('phot
我正在使用 pytesseract 包中的 image_to_string 函数将单个图片文件的多个部分转换为字符串。除此图像外,所有部分均正常工作: 这是我用来转换它的脚本: from PIL im
我正在尝试使用 OpenCV 和 pytesseract 的 image_to_string() 方法从图像中提取数字,但输出效果不佳。 我尝试了一些预处理方法,如调整大小和噪声过滤器,但仍然无法获得
我最近在 python 中使用了 tesseract OCR,当我尝试从 tesseract 导入 image_to_string 时,我一直遇到错误。 导致问题的代码: # Perform OCR
首先,我想说我知道 pytesser 不适用于 Python 3.4,但我从 http://ubuntuforums.org/archive/index.php/t-1916011.html 中读到p
我正在尝试从 tif 或 tiff 图像文件中读取文本。这些文件有多个页面。 当我打印数组时,我只得到 true,然后没有文本。但是,当我使用 .png 文件时,我能够打印文本。 下面是我的代码。 f
我是 python 编码的新手。我正在使用 Pillow 。以下是代码: >>> from PIL import Image >>> from pytesseract import*
我是一名优秀的程序员,十分优秀!