zoukankan      html  css  js  c++  java
  • Python2.7利用Tesseract进行中英文图像识别

    背景环境:  win8.1  64位   python2.7.13  
    本以为会很简单,结果在配置环境这块上花了很多时间,踩了几个坑,最后自己看英文文档和log才解决问题。
    打开网站  
    https://pypi.python.org/pypi/pytesseract  
    https://github.com/tesseract-ocr/tesseract/wiki
    https://github.com/tesseract-ocr/tesseract/wiki/Downloads
    http://www.pythonware.com/products/pil/
    找到并下载安装tesseract-ocr-setup-4.00.00dev.exe文件   下载中文训练库chi_sim.traineddata 
    将安装文件路径  添加到环境变量中的PATH 和 Path中去 ,在系统变量中添加一个TESSDATA_PREFIX,变量值还是文件路径
    我的是D:programfiles esseractTesseract-OCR
    打开cmd安装  pip install pytesseract    

    去C:Python27Libsite-packages 下找到PIL卸载 然后 去下载 PIL-1.1.7.win32-py2.7.exe  并安装 

    # -*- coding: utf-8 -*-
    try:
        import Image
    except ImportError:
        from PIL import Image
    import pytesseract
    
    img = Image.open('test2.png')
    img.load()
    text = pytesseract.image_to_string(img, lang='chi_sim')
    print(text)

    最后找张png的图放在和这个文件同目录下   完事了

    几个坑: 
    :from . import VERSION, PILLOW_VERSION, _plugins ueError: Attempted relative
    不知道什么鬼,后来直接把C:Python27Libsite-packagesPIL 给删了 重新安装这个库
    pytesseract.pytesseract.TesseractError: (1, u'Error opening data file D:\programfiles\tesseract\Tesseract-OCR/chi_sim.traineddata')
    这里需要将chi_sim.traineddata放在指定目录下,而不是 $path essdata essconfigs下 
    总结:  看官方教程  百度上搜索的太旧了   stackoverflow 也是  

  • 相关阅读:
    Chrome cookies folder
    Fat URLs Client Identification
    User Login Client Identification
    Client IP Address Client Identification
    HTTP Headers Client Identification
    The Personal Touch Client Identification 个性化接触 客户识别
    购物车 cookie session
    购物车删除商品,总价变化 innerHTML = ''并没有删除节点,内容仍存在
    453
    购物车-删除单行商品-HTMLTableElement.deleteRow()
  • 原文地址:https://www.cnblogs.com/zeroones/p/8329537.html
Copyright © 2011-2022 走看看