【问题标题】:Using tesseract and opencv to extract text from image使用 tesseract 和 opencv 从图像中提取文本
【发布时间】:2020-06-12 09:52:33
【问题描述】:

This is the image in the code above and nothing is outputed

我正在使用 pytesseract 和 opencv 来识别车牌上的文字,但是很多时候当我运行下面的代码时,我使用的图像没有输出任何文字

import cv2
import imutils
import numpy as np
import pytesseract as tess
tess.pytesseract.tesseract_cmd =r'C:\Users\raul__000\AppData\Local\Tesseract-OCR\tesseract.exe'

# read image file
img = cv2.imread("Plate_images/plate14.jpg")
cv2.imshow("Image", img)
cv2.waitKey(0)

# RGB to Gray scale conversion
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.imshow("1 - Grayscale Conversion", gray)
cv2.waitKey(0)

# Noise removal with iterative bilateral filter(removes noise while preserving edges)
gray = cv2.bilateralFilter(gray, 11, 17, 17)
cv2.imshow("2 - Bilateral Filter", gray)
cv2.waitKey(0)

# thresholding the grayscale image
gray = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
cv2.imshow("3 - Thresh Filter", gray)
cv2.waitKey(0)

# Dilation adds pixels to the boundaries of objects in an image
kernel = np.ones((5,5),np.uint8)
gray = cv2.dilate(gray, kernel, iterations = 1)
cv2.imshow("4 - dilation Filter", gray)
cv2.waitKey(0)

# use tesseract to convert image to string
text = tess.image_to_string(gray, lang="eng", config='--psm 6')

print(text)

This is the image in the code above and nothing is outputed

【问题讨论】:

    标签: tesseract python-tesseract


    【解决方案1】:

    您的第四步是从图像中删除所有文本

    使用cv2.imshow("4 - dilation Filter", gray)时应该可以看到

    如果您删除第三步并运行 tesseract,您应该会看到输出。

    【讨论】:

      猜你喜欢
      • 2018-06-18
      • 2012-05-23
      • 1970-01-01
      • 1970-01-01
      • 2021-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-08
      相关资源
      最近更新 更多