Почему я не могу распознать простой альфа-текст из изображений, используя python,pytesseract,cv2
Я пытаюсь определить текст на кнопках и меню, чтобы убедиться, что они правильно идентифицированы, прежде чем нажимать их. Любая помощь будет принята с благодарностью.
Я пытался изменить цветовые шкалы, изменяя размеры и улучшая изображения, но ничто не может определить то, что мне кажется простым текстом. Я приложу некоторые изображения и код, который был ближе всего. Я пытался использовать следующие сайты и помогает, но пока ничего:
" https://medium.freecodecamp.org/getting-started-with-tesseract-part-ii-f7f9a0899b3f" или " использовать pytesseract для распознавания текста из изображения" или " https://www.pyimagesearch.com/2018/08/20/opencv-text-detection-east-text-detector/"
def I_get_Image_and_Extract_Data(self,image):
#Use an Image to find it on a screen then check the matched image has the correct text before clicking.
import PIL
from PIL import Image, ImageEnhance, ImageFilter
import pytesseract
from pytesseract import image_to_string
ratio = Decimal(4)
cvimg = cv2.imread(image)
cvimg2 = cv2.resize(cvimg, None, fx = ratio, fy = ratio, interpolation = cv2.INTER_CUBIC) # Resize image per calculation above, Also tried different rezizing methods.
cv2.imwrite("c:\\Temp\\cvtest.png",cvimg2)
img = Image.open("c:\\Temp\\cvtest.png")
img = img.convert('L')
#img = img.filter(ImageFilter.MedianFilter()) ##This completely breaks any recognition
enhancer = ImageEnhance.Contrast(img)
img = enhancer.enhance(10)
img2 = PIL.ImageOps.crop(img,4*ratio)
#img2 = img2.convert('1') ##This completely breaks any recognition
img2.save("c:\\Temp\\test.png") ##Save a copy just to see what it looks like
text = image_to_string(Image.open("c:\\Temp\\test.png"),config='-c tessedit_char_whitelist=0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ --psm 6 --oem 1',lang='eng') ##--psm 6,7,9,10 get closest for different images.
print("Text Found in Image is: '" + text + "'")
Любая помощь, чтобы получить последовательно извлеченный набор текста: все изображения можно найти здесь: https://imgur.com/gallery/pwOz67v
Ближайший результат мне удалось получить так далеко ниже:
currFileName: .\Resources\Images\DNMS\Overview\2560_1600\Clean\All.PNG
Text Found in Image is: --psm 6-'All'
Text Found in Image is: --psm 7-'All'
Text Found in Image is: --psm 9-'Pas'
Text Found in Image is: --psm 10-'All'
currFileName: .\Resources\Images\DNMS\Overview\2560_1600\Clean\B.PNG
Text Found in Image is: --psm 6-'Ss)'
Text Found in Image is: --psm 7-'B'
Text Found in Image is: --psm 9-'om.'
Text Found in Image is: --psm 10-'a'
currFileName: .\Resources\Images\DNMS\Overview\2560_1600\Clean\CCG.PNG
Text Found in Image is: --psm 6-'CC
|'
Text Found in Image is: --psm 7-'ve'
Text Found in Image is: --psm 9-'SS'
Text Found in Image is: --psm 10-'ve'
currFileName: .\Resources\Images\DNMS\Overview\2560_1600\Clean\CCW.PNG
Text Found in Image is: --psm 6-'CC
VA'
Text Found in Image is: --psm 7-''
Text Found in Image is: --psm 9-'Wwe'
Text Found in Image is: --psm 10-'es'
currFileName: .\Resources\Images\DNMS\Overview\2560_1600\Clean\CBD.PNG
Text Found in Image is: --psm 6-'CBD'
Text Found in Image is: --psm 7-'CBD'
Text Found in Image is: --psm 9-''
Text Found in Image is: --psm 10-'CBD'
currFileName: .\Resources\Images\DNMS\Overview\2560_1600\Clean\DW.PNG
Text Found in Image is: --psm 6-'DD) VV'
Text Found in Image is: --psm 7-'DD) VV'
Text Found in Image is: --psm 9-'DW'
Text Found in Image is: --psm 10-'DD) VV'
currFileName: .\Resources\Images\DNMS\Overview\2560_1600\Clean\E.PNG
Text Found in Image is: --psm 6-'E'
Text Found in Image is: --psm 7-'E'
Text Found in Image is: --psm 9-'E'
Text Found in Image is: --psm 10-'E'
currFileName: .\Resources\Images\DNMS\Overview\2560_1600\Clean\Ma.PNG
Text Found in Image is: --psm 6-'ais)'
Text Found in Image is: --psm 7-'ais)'
Text Found in Image is: --psm 9-'aks'
Text Found in Image is: --psm 10-'ais)'
currFileName: .\Resources\Images\DNMS\Overview\2560_1600\Clean\Mu.PNG
Text Found in Image is: --psm 6-'Mu'
Text Found in Image is: --psm 7-'Mu'
Text Found in Image is: --psm 9-'nn'
Text Found in Image is: --psm 10-'Mu'
currFileName: .\Resources\Images\DNMS\Overview\2560_1600\Clean\N.PNG
Text Found in Image is: --psm 6-'iN'
Text Found in Image is: --psm 7-'.'
Text Found in Image is: --psm 9-'a'
Text Found in Image is: --psm 10-'NU'
currFileName: .\Resources\Images\DNMS\Overview\2560_1600\Clean\S.PNG
Text Found in Image is: --psm 6-'S'
Text Found in Image is: --psm 7-'S'
Text Found in Image is: --psm 9-'ce'
Text Found in Image is: --psm 10-'S'
currFileName: .\Resources\Images\DNMS\Overview\2560_1600\Clean\ControlWindow.PNG
Text Found in Image is: --psm 6-'Navigate Diagram Alarms Alarms/Events Reports
2.00
a
Bank Inner | |
Bank Main | |
Bank West | |'
Text Found in Image is: --psm 7-'= 7] Alarms Alarms/Events Reports'
Text Found in Image is: --psm 9-'='
Text Found in Image is: --psm 10-'=|'