我有一个图像,我想使用tesseract和python从中提取文本。我只想识别一组特定的字符,所以我使用tessedit_char_whitelist=1234567890CBDE
作为配置。然而,现在tesseract似乎不再认识到线条之间的间隙。是否有一些字符可以添加到白名单中,以便它再次将文本识别为单个文本
以下是白名单后的图像:
以下是白名单前的图像:
下面是用于绘制方框和识别字符的代码,以防您产生疑问:
#configuring parameters for tesseract
# whitlist = "-c tessedit_char_whitelist=1234567890CBDE"
custom_config = r'--oem 3 --psm 6 '
# now feeding image to tesseract
details = pytesseract.image_to_data(threshold_img, output_type=Output.DICT, config=custom_config, lang='eng')
print(details.keys())
total_boxes = len(details['text'])
for sequence_number in range(total_boxes):
# confidence above 30 %
CONFIDENCE = 0
if int(details['conf'][sequence_number]) >= CONFIDENCE:
(x, y, w, h) = (details['left'][sequence_number], details['top'][sequence_number], details['width'][sequence_number], details['height'][sequence_number])
threshold_img = cv2.rectangle(threshold_img, (x, y), (x + w, y + h), (0, 255, 0), 2)
# display image
cv2.imshow('captured text', threshold_img)
cv2.imwrite("before.png", threshold_img)
# Maintain output window until user presses a key
cv2.waitKey(0)
# Destroying present windows on screen
cv2.destroyAllWindows()
编辑:
这是我想从中提取文本的原始图像,目标是将其写入矩阵:
所需矩阵将采用以下形式:
content = [
["1C", "55", "55", "E9", "BD"],
# ...
["1C", "1C", "55", "BD", "BD"]
]
一种解决办法是:
其思想是分别获取每个元组,对其进行上采样,然后应用逆二进制阈值。由于字体的原因,Tesseract误解了几个元组。例如,如果您查看字符
D
,它看起来像O
。如果你想要100%的准确率,那么我建议你train the tesseract。另外,请确保尝试使用其他page-segmentation-modes以下是阵列输出:
代码:
相关问题 更多 >
编程相关推荐