美文网首页
raspberry ocr

raspberry ocr

作者: star_walker | 来源:发表于2021-09-06 12:15 被阅读0次

    安装依赖

    sudo apt-get install g++ autoconf automake libtool autoconf-archive pkg-config libpng-dev libjpeg8-dev libtiff5-dev zlib1g-dev
    ————————————————
    版权声明:本文为CSDN博主「huanghuangyuni」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/huanghuangyuni/article/details/78766508
    

    安装Leptonica

    sudo apt-get install libleptonica-dev
    

    安装tesseract

    sudo apt-get install tesseract-ocr
    

    安装pytesseract

    pip install pytesseract
    

    启动python,新建文件夹输入以下代码

    #!/usr/bin/env python
    
    from PIL import Image
    import pytesseract
    text=Image.open('/home/pi/Downloads/test.png')
    #print(text)
    print(pytesseract.image_to_string(text))
    ————————————————
    版权声明:本文为CSDN博主「huanghuangyuni」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/huanghuangyuni/article/details/78766508
    

    保存并运行

    保存测试图片 /home/pi/Downloads/test.png

    ocr-en.png

    运行

    l@l:~/src/wx-play/ocr$ vim ocr-test.py
    l@l:~/src/wx-play/ocr$ python3 ocr-test.py 
     
    
    This is a lot of 12 point text to test the
    ocr code and see if it works on all types
    of file format.
    
    The quick brown dog jumped over the
    lazy fox. The quick brown dog jumped
    over the lazy fox. The quick brown dog
    jumped over the lazy fox. The quick
    brown dog jumped over the lazy fox.
    

    中文识别

    要识别中文,需要先下载中文语言包chi_sim.traineddata放到树莓派的:/usr/share/tesseract-ocr/tessdata文件夹下,
    之后我们将

    words = image_to_string(pil_im,"eng").strip()
    替换为:
    words = image_to_string(pil_im,"chi_sim").strip()
    

    Reference links:

    相关文章

      网友评论

          本文标题:raspberry ocr

          本文链接:https://www.haomeiwen.com/subject/ttuewltx.html