如何在图像中的文本区域周围制作边界框? (即使文字偏斜!!)

问题描述 投票:0回答:1

我正在尝试从任何消费者产品广告中截取的屏幕截图中检测并抓取文本。

我的代码以一定的准确度工作,但未能在倾斜的文本区域周围制作边界框。

最近我尝试了Google Vision API,它几乎在每个可能的文本区域周围都有边框,并且可以非常准确地检测该区域中的文本。我很好奇我怎么能达到相同或类似的目的!

我的测试图片:

enter image description here

绑定框后的Google Vision API:

enter image description here

先感谢您:)

opencv imagemagick bounding-box google-vision pytesseract
1个回答
2
投票

有一些开源视觉软件包能够在嘈杂的背景图像中检测文本,与Google的Vision API相当。

您可以使用Zhou等人称为EAST(高效精确场景文本检测器)的固定卷积层简单架构。 https://arxiv.org/abs/1704.03155v2

使用Python:

https://www.dropbox.com/s/r2ingd0l3zt8hxs/frozen_east_text_detection.tar.gz?dl=1下载预训练模型。将模型提取到当前文件夹。

您将需要OpenCV> = 3.4.2来执行以下命令。

import cv2
import math
net = cv2.dnn.readNet("frozen_east_text_detection.pb")   #This is the model we get after extraction
frame = cv2.imread(<image_filename>)
inpWidth = inpHeight = 320  # A default dimension
# Preparing a blob to pass the image through the neural network
# Subtracting mean values used while training the model.
image_blob = cv2.dnn.blobFromImage(frame, 1.0, (inpWidth, inpHeight), (123.68, 116.78, 103.94), True, False)

现在我们必须定义输出层,这些输出层产生检测到的文本的位置值及其置信度分数(通过Sigmoid函数)

output_layer = []
output_layer.append("feature_fusion/Conv_7/Sigmoid")
output_layer.append("feature_fusion/concat_3")

最后,我们将通过网络进行前向传播以获得所需的输出。

net.setInput(image_blob)
output = net.forward(output_layer)
scores = output[0]
geometry = output[1]

这里我使用了opencv的github页面中定义的解码函数https://github.com/opencv/opencv/blob/master/samples/dnn/text_detection.py将位置值转换为box坐标。 (第23至75行)。

对于盒子检测阈值,我使用了0.5的值,而对于非最大抑制,我使用了0.3。您可以尝试不同的值来获得更好的边界框。

confThreshold = 0.5
nmsThreshold = 0.3
[boxes, confidences] = decode(scores, geometry, confThreshold)
indices = cv2.dnn.NMSBoxesRotated(boxes, confidences, confThreshold, nmsThreshold)

最后,将框覆盖在图像中检测到的文本上:

height_ = frame.shape[0]
width_ = frame.shape[1]
rW = width_ / float(inpWidth)
rH = height_ / float(inpHeight)

for i in indices:
    # get 4 corners of the rotated rect
    vertices = cv2.boxPoints(boxes[i[0]])
    # scale the bounding box coordinates based on the respective ratios
    for j in range(4):
        vertices[j][0] *= rW
        vertices[j][1] *= rH
    for j in range(4):
        p1 = (vertices[j][0], vertices[j][1])
        p2 = (vertices[(j + 1) % 4][0], vertices[(j + 1) % 4][1])
        cv2.line(frame, p1, p2, (0, 255, 0), 3)

# To save the image:
cv2.imwrite("maggi_boxed.jpg", frame)

Maggi's Ad with bounding boxes

我没有尝试过不同的阈值。更改它们肯定会提供更好的结果,并且还会删除徽标作为文本的错误分类。

注意:该模型是在英语语料库上训练的,因此不会检测到印地语单词。您还可以阅读描述其标记的测试数据集的文章。


0
投票

您需要检查是否有任何库提供文本坐标,然后您可以在文本周围绘制框。 OCR库

1)Python pyocr和tesseract ocr over python

2)使用R语言(从PDF中提取文本;执行OCR;所有在R中)

3)Java / Pyspark中的Tesseract库

4)Apache Tika

5)Python - OpenCV - 使用kNN的手写数据的OCR

6)你可以通过OpenCV和Python做同样的事情。

免费的OCR软件

谷歌和惠普的Tesseract谷歌保持微软文档影像(MODI)(假设我们大多数人都拥有Windows操作系统)Microsoft One Note Microsoft Oxford Project API(此API在一段时间内免费)FreeOCR(这是再次基于Tesseract引擎)还有更多,但这些是最好的,并且在所有这些中,如果您正在寻找准确性,Microsoft Document Imaging可以做得更好。如果你正在寻找手写文本ocr转换,那么谷歌的Keep会做得更好。

商业产品

Adobe Acrobat Pro(RTF文件格式为您提供最佳结果)Captiva Abbyy Informatica(不确定Informatica中的哪个模块)IBM Datacapture(Datacap)(IBM Watson)如果准确性只是您的主要约束,那么您的服务中就会出现前所未有的数据访问(captricity)拥有99%的准确率,因为他们挤满了源人并使他们转换手写文本而不影响安全性。

© www.soinside.com 2019 - 2024. All rights reserved.