为什么我无法使用python,pytesseract,cv2从图像中识别简单的Alpha文本

时间:2019-01-18 02:25:32

标签: python image-recognition python-tesseract

我正在尝试识别按钮和菜单上的文本,以确保它们是正确识别的文本,然后再单击它们。任何帮助将不胜感激。

我尝试过修改色阶,调整图像大小和增强图像,但是似乎没有什么能够识别出看起来像是简单文本的内容。我将附加一些图像和最接近的代码。 我尝试过使用以下网站,但到目前为止没有帮助:

https://medium.freecodecamp.org/getting-started-with-tesseract-part-ii-f7f9a0899b3f”或 “ use pytesseract to recognize text from image”或 “ 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 + "'")

获得一致提取的文本集的任何帮助: 所有图片都可以在这里找到:http://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-'=|'

0 个答案:

没有答案