假设我的用户去了他们办公室的扫描仪。扫描仪能够生成扫描文档的 PDF。这本质上就是我拥有的文件类型。
我想要做的是从这个 PDF 中提取文本。这不是“第一代”pdf,因为文本未嵌入到 pdf 中。文本嵌入到 PDF 的图像中。
PDFBox 的 iText 中是否有允许检索此数据的功能?如果可能的话,我试图避免对图像进行 OCR。我希望 IText 或 PDFBox 中有内置的东西可以做到这一点。
请注意,我并不是在谈论从 pdf 中提取“正常”文本,如下所述:How to get raw text from pdf file using java
我需要输入图像和坐标。输入坐标中存在的文本必须作为输出读取。如何使用节点超立方体来做到这一点?
我收到以下错误:
ModuleNotFoundError:没有名为“Image”的模块
运行以下 OCR 脚本时:
import Image
from tesseract import image_to_string
print(image_to_string(Image.open('marlboro.png'), lang='eng'))
Run Code Online (Sandbox Code Playgroud)
我通过 Anaconda 使用 Spider 并安装了 Pillow。
您好,我正在尝试消除保存在位图中的图像的所有橙色色调,我需要使用超立方体在图像中进行 OCR,扫描文档的橙色似乎阻碍了在文本中产生错误的过程,我已经尝试过用photoshop去除橙色I,使OCR工作完美,主要问题是像素并不都是相同的颜色,它们是橙色但深浅不同
Bitmap modificar = new Bitmap("imagenamodificar.png");
for (int ycount2 = 0; ycount2 < modificar.Height; ycount2++)
{
for (int xcount2 = 0; xcount2 < modificar.Width; xcount2++)
{
if (modificar.GetPixel(xcount2, ycount2) == Color.Orange)
{
modificar.SetPixel(xcount2, ycount2, Color.White);
}
}
}
Run Code Online (Sandbox Code Playgroud)
该代码绝对不执行任何操作,图像保持不变。
然后我想到与像素 (0,0) 进行比较,因为它始终是我想要消除的颜色。
Bitmap modificar = new Bitmap("imagenamodificar.png");
for (int ycount2 = 0; ycount2 < modificar.Height; ycount2++)
{
for (int xcount2 = 1; xcount2 < modificar.Width; xcount2++)
{
if (modificar.GetPixel(xcount2, ycount2) == modificar.GetPixel(0,0))
{
modificar.SetPixel(xcount2, ycount2, Color.White);
}
}
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试对此类图像进行 OCR:
不幸的是,由于字符周围有噪声点,tesseract 无法检索该数字。
我尝试使用 ImageMagick 来提高图像质量,但没有成功。
例子:
convert input.tif -level 0%,150% output.tif
convert input.tif -colorspace CMYK -separate output_%d.tif
Run Code Online (Sandbox Code Playgroud)
有什么方法可以有效地检索此类图像中的字符吗?
非常感谢。
在示例图像中(仅作为参考,我的图像将具有相同的图案),一个页面具有完整的水平文本,其他页面具有两个水平文本列。
如何在python中自动检测文档的模式并逐一读取另一列数据?
我将 Tesseract OCR 与 Psm 6 一起使用,它是水平读取的,这是错误的。
当使用 Google Vision 在菜单上运行文本检测时,其 API 的响应太大,并且返回了太多我不需要的数据。我只想要菜单中的文本,而不是响应附带的所有坐标。在我读过的任何文档中,我找不到任何有关缩小响应范围的内容。有人知道如何指定响应中返回哪些字段吗?
这是我的要求:
POST: https://vision.googleapis.com/v1/images:annotate?key=<MY_KEY>
BODY:
{
"requests": [
{
"image": {
"content": "...base64-encoded-image-content..."
},
"features": [
{
"type": "TEXT_DETECTION"
}
]
}
]
}
Run Code Online (Sandbox Code Playgroud) 我目前正在尝试从小屏幕截图中检测数字。然而,我发现准确性相当差。我一直在使用 OpenCV,图像以 RGB 格式捕获并转换为灰度,然后使用全局值执行阈值处理(我发现自适应效果不太好)。
下面是其中一个数字的灰度示例,后面是阈值保持后的图像示例(数字范围为 1-99)。请注意,图像的初始屏幕截图非常小,因此被放大。
任何有关如何使用 OpenCV 或完全不同的系统提高准确性的建议都非常感谢。下面包含一些代码,该函数传递数字的 RGB 屏幕截图。
def getNumber(image):
image = cv2.resize(image, (0, 0), fx=3, fy=3)
img = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
thresh, image_bin = cv2.threshold(img, 125, 255, cv2.THRESH_BINARY)
image_final = PIL.Image.fromarray(image_bin)
txt = pytesseract.image_to_string(
image_final, config='--psm 13 --oem 3 -c tessedit_char_whitelist=0123456789')
return txt
Run Code Online (Sandbox Code Playgroud) 我有一个pdf 文件,我想从中提取文本。我使用 tesseract 进行 OCR,效果很好。但我的问题是它无法识别文档的 2 列格式,因此它将 2 列合并在一起。
我想在垂直(页面中间)和水平(页面顶部)线上分割文档,然后将其输入超正方体。所以我做了以下事情
预处理步骤:
# color to gray
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# edge detection
edges = cv2.Canny(gray, 500, 1000, apertureSize=7)
# dialate
kernel = np.ones((5,5),np.float32)/25
edges = cv2.dilate(edges, kernel, iterations=1)
# blur
blur = cv2.GaussianBlur(edges, (7, 7), 0)
Run Code Online (Sandbox Code Playgroud)
现在,我进行线路检测:
minLineLength = 1000
maxLineGap = 500
lines = cv2.HoughLinesP(processed_img, 1, np.pi, 2, minLineLength, maxLineGap)
for line in lines:
x1, y1, x2, y2 = line[0]
cv2.line(img, (x1, y1), (x2, y2), (0, …Run Code Online (Sandbox Code Playgroud) 我的错误在标题中进行了解释。我该如何解决这个问题?我似乎找不到任何循环导入,但无论如何我都会收到错误。是模块设计不好还是我做错了什么?
import easyocr
import argparse
import cv2
def cleanup_text(text):
# strip out non-ASCII text so we can draw the text on the image
# using OpenCV
return "".join([c if ord(c) < 128 else "" for c in text]).strip()
# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True,
help="path to input image to be OCR'd")
ap.add_argument("-l", "--langs", type=str, default="en",
help="comma separated list of languages to OCR")
ap.add_argument("-g", "--gpu", type=int, default=-1,
help="whether or not GPU should …Run Code Online (Sandbox Code Playgroud)