使用tesseract和opencv从图像中提取文本

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

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个回答
0
投票

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

enter image description here

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

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

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