Вот мой код и процессы:
- Сначала выровняйте изображение по шаблону. (Я добавлю шаблон).
- Установите разрешение изображения с помощью кода ниже.
Код: Выделить всё
def set_image_dpi(file_path):
IMAGE_SIZE = 1800
im = Image.open(file_path)
length_x, width_y = im.size
factor = max(1, int(IMAGE_SIZE / length_x))
size = factor * length_x, factor * width_y
# size = (1800, 1800)
im_resized = im.resize(size, Image.ANTIALIAS)
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.jpg')
temp_filename = temp_file.name
im_resized.save(temp_filename, dpi=(300, 300))
return temp_filename
- Затем я удаляю шум и обрезаю уверенные рамки:
Код: Выделить всё
def remove_noise(image):
return cv2.fastNlMeansDenoisingColored(image, None, 10, 10, 7, 15)
if box.conf[0] > 0.20:
class_name = classes_names[int(box.cls[0])]
custom = False
custom_config_str = ""
[x1, y1, x2, y2] = box.xyxy[0]
# convert to int
x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2)
cropped = frame[y1:y2, x1:x2]
cropped = remove_noise(cropped)
cropped = cv2.cvtColor(cropped, cv2.COLOR_BGR2GRAY)
# blur
blur = cv2.GaussianBlur(cropped, (0, 0), sigmaX=99, sigmaY=99)
# divide
cropped = cv2.divide(cropped, blur, scale=255)
Код: Выделить всё
text = pytesseract.image_to_string(
cropped,
config=None if custom != True else "-psm 6,
lang="tur")
[img]https://i.sstatic. net/YTIrvHx7.png[/img]
текст: DJTICARIADI \n

текст: ДИМАРКАСИ \nRENALLI

текст: /Y.3/KULLANIMAMACI \n ЙОЛКУНАКЛИ-ХУСУСИДИ

Подробнее здесь: https://stackoverflow.com/questions/790 ... mit-reader