【问题标题】:Why doesn't pytesseract recognize any text in this image?为什么 pytesseract 无法识别此图像中的任何文本?
【发布时间】:2021-01-07 16:10:48
【问题描述】:

我有这张图片input image 我正在尝试在其上应用文本检测和 ocr, 然而,即使在预处理(二进制阈值等)之后,pytesseract 也不会返回任何输出。文本检测的目的是提高ocr输出,我不太关心获取边界框。

下面是我的代码:

image = cv2.imread('image.jpg')

grey = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

ret,thresh1 = cv2.threshold(grey,127,255,cv2.THRESH_BINARY)

image = pytesseract.image_to_data(thresh1, output_type=Output.DICT)
image = cv2.bitwise_not(image)

检查结果没有无意义的输出,有什么可以改进的吗?

【问题讨论】:

  • 看看:Improving the quality of the output。 ...答案是:使用 tesseract,您需要对图像进行预处理。至少它需要是黑白的。
  • 感谢您的评论,虽然我的图像已经过预处理并且是黑白的,这是通过发布的代码实现的
  • 什么是 output_type=Output.DICT?
  • 它将 image_to_data 的输出存储在字典中
  • 那么,您为什么要尝试将 openCV 函数(矩阵数组)应用于字典?你到底想要什么?是为每个单词/数字绘制矩形(在图像中)?

标签: computer-vision ocr python-tesseract east-text-detector


【解决方案1】:

试试这个代码:

import pytesseract
import cv2
image = cv2.imread('ccl6t.png')
pytesseract.pytesseract.tesseract_cmd = r'k:\Tesseract\tesseract.exe' #need change!
grey = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
ret,thresh1 = cv2.threshold(grey,127,255,cv2.THRESH_BINARY_INV)
cv2.imwrite('tresh.png', thresh1)
words = pytesseract.image_to_data(thresh1, lang='eng',config='--psm 3 --oem 1 ')
print(str(words))

【讨论】:

  • 我试过你的代码,但仍然没有得到预期的输出。我想在图像中找到文本并提取/识别名称
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-11-14
  • 2021-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-23
  • 1970-01-01
相关资源
最近更新 更多