Просматривал различные сайты, на которых есть код для улучшения качества изображения, но он не работал. Кто-нибудь может мне помочь с этим? Желаемый результат должен быть «I6M-9U».

Код: Выделить всё
def get_text_from_image(image: cv2.Mat) -> str:
pytesseract.pytesseract.tesseract_cmd = r'C:\Tesseract-OCR\tesseract.exe'
# Crop image to only get the piece I am interested in
top, left, height, width = 25, 170, 40, 250
try:
crop_img = image[top:top + height, left:left + width]
# Make it bigger
resize_scaling = 1500
resize_width = int(crop_img.shape[1] * resize_scaling / 100)
resize_height = int(crop_img.shape[0] * resize_scaling / 100)
resized_dimensions = (resize_width, resize_height)
# Resize it
crop_img = cv2.resize(crop_img, resized_dimensions, interpolation=cv2.INTER_CUBIC)
return str(pytesseract.image_to_string(crop_img, config="--psm 6"))
Код: Выделить всё
ret, thresh1 = cv.threshold(image, 120, 255, cv.THRESH_BINARY +
cv.THRESH_OTSU)
cv.imshow("image", thresh1)
Подробнее здесь: https://stackoverflow.com/questions/784 ... seract-ocr