Чтение изображения с низким разрешением с помощью pytesseract - PullRequest
0 голосов
/ 24 ноября 2018

Я пытаюсь прочитать некоторые статистические данные с обрезанных (вручную) разделов таблиц в pdf-файлах.

Вот изображение, которое я пытаюсь обработать

Текущий результат, который я получаю, содержит большинство чисел, но не весь текст, как показано ниже:

 Hmuwinu'fg. cm’: -009,d1-I (F -o.761.l= .om, 
 Tamar wuall ma: 2 1.41(F-o.167
 Tao! hr aubgrwp dimes: Nol wvwe

Я пытался использовать интерполяции, отличные от межкубических, на этапе изменения размера, и пытался изменить размер ядра, но 1x1, кажется, работает лучше.

Вот текущий код:

# import the packages
from PIL import Image
import pytesseract
import numpy as np
import argparse
import cv2
import os

# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True,help="path to input image to OCR'd")
ap.add_argument("-p","--preprocess",type=str,default="thresh",help="type of preprocessing to be done")
args = vars(ap.parse_args())

#load the example image 
image = cv2.imread(args["image"])

# Rescale image 
image = cv2.resize(image,None,fx=1.5,fy=1.5,interpolation=cv2.INTER_CUBIC)

#Apply dilation and erosion to remove some noise
kernel = np.ones((1,1),np.uint8)
image = cv2.dilate(image,kernel,iterations=1)
image = cv2.erode(image,kernel,iterations=1)

#Convert it to grayscale
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)

# check to see if we should apply thresholding to process image
if args["preprocess"] == "thresh":
    gray = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]

# make a check to see if median blurring should be applied
elif args["preprocess"] == "blur":
    gray = cv2.medianBlur(gray,3)

#write the gray scale image to a disk as a temp file so we can OCR it
filename = "{}.png".format(os.getpid())
cv2.imwrite(filename,gray)

#load the image as a PIL/pillow image, apploy OCR, then delete temp file
text = pytesseract.image_to_string(Image.open(filename))
os.remove(filename)
print(text)

# show the output images
cv2.imshow("Image",image)
cv2.imshow("Output",gray)
cv2.waitKey(0)

Любые предложения или методы действительно приветствуются.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...