Итак, я получил несколько изображений и попытался применить к ним tesseract с помощью Python, в данном случае изображения. это номерной знак, поэтому я не буду показывать исходное изображение, но после некоторой предварительной обработки я получаю следующее:
[img]https://i.sstatic.net /1KckEIK3.jpg[/img]
Кажется, это довольно простое изображение для получения текста, но я всегда получаю 624830, поэтому 830 подойдет, но 624 должен быть GZX.
Это мой код:
Код: Выделить всё
import pytesseract
import cv2
# Opening the image
img = cv2.imread("plate.jpg")
# Preprocess (Better performance)
w,h,_ = img.shape
img = cv2.resize(img, (w*2,h*2))
img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
img = cv2.medianBlur(img,5)
img = cv2.threshold(img,0,255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)[1]
# Get a slice of the image with just the text to improve performance
box = []
data = pytesseract.image_to_data(img, config=r'--oem 3', output_type=pytesseract.Output.DICT)
n_boxes = len(data['level'])
for i in range(n_boxes):
(x, y, w, h) = (data['left'][i], data['top'][i], data['width'][i], data['height'][i])
if int(data['conf'][i]) > 0:
box.append((x, y, x + w, y + h))
h, w = img.shape
for box in box:
x_min, y_min, x_max, y_max = box
# Add some padding ensuring we do not get out of the image
x_min_pad = max(0, x_min - 5)
y_min_pad = max(0, y_min - 5)
x_max_pad = min(w, x_max + 5)
y_max_pad = min(h, y_max + 5)
# Get the slice
slice = img[y_min_pad:y_max_pad, x_min_pad:x_max_pad]
# Inference with LSTM on the slice
print(pytesseract.image_to_string(slice, config='--psm 8 --oem 3'))
Подробнее здесь: https://stackoverflow.com/questions/790 ... tion-fails