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)
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页面中定义的decode函数https://github.com/opencv/opencv/blob/master/samples/dnn/text_detection.py,将位置值转换为框坐标(第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)
我没有尝试过不同的阈值值。改变它们肯定会产生更好的结果,并消除将标志错误分类为文本的情况。
注意:该模型是在英语语料库上训练的,因此不会检测出印地语单词。您也可以阅读论文,其中概述了测试数据集的基准。
Adobe Acrobat Pro(RTF文件格式可获得最佳结果) Captiva Abbyy Informatica(不确定是Informatica中的哪个模块) IBM Datacapture(Datacap)(IBM Watson) 如果准确性是您唯一的主要限制,则有类似于Unprecedented Data Access at your Service(captricity)的东西,它以99%的准确性自豪,因为他们通过众包人员将手写文本转换而不会影响安全性。