我正在尝试将黑白图像文件(附加)转换为字符串。它不起作用
结果 BX 5573 1
number plate image in black and white
from skimage.filters import threshold_otsu
from skimage.segmentation import clear_border
from skimage.measure import label, regionprops
from skimage.morphology import closing, square
from skimage.color import label2rgb
import matplotlib.patches as mpatches
from pytesseract import image_to_string
from PIL import ImageEnhance
image_file="ocr_num5.jpg"
imagem = cv2.imread(image_file)
cleared = clear_border(imagem)
fig, (ax1, ax2) = plt.subplots(1,2, figsize=(10, 6))
ax1.imshow(imagem,"gray")
img_ocr = Image.fromarray(imagem)
width, height = img_ocr.size
new_size = width*6, height*6
img_ocr = img_ocr.resize(new_size, Image.LANCZOS)
img_ocr = img_ocr.convert('L')
img_ocr = img_ocr.point(lambda x: 0 if x < 128 else 255, '1')
ax2.imshow(img_ocr)
str_ocr = image_to_string(img_ocr, lang='eng',config='-c\
tessedit_char_whitelist=0123456789ABCDEFGHIJKLMNOPQRSTUVWXY -psm 6')
print(" "+str_ocr)