Python EasyOCR 文字识别

发布于:2023-03-20 ⋅ 阅读:(615) ⋅ 点赞:(0)

前言:

      在现在人脸识别,身份证识别,图片识别已经流行。刷脸支付,指纹支付、刷脸支付等等。
  做为一名技术工程师,是不是好奇,这是怎么做到的呢。这就带你揭开神秘的面纱,一趟究竟。

选型

在图片识别的技术选型中,有比较常见PHP语言,Java语言,Go语言,C语言。为什么是Python。原因无外乎安装方便,使用简单,不用研究图像识别的底层原理,不亏是胶水语言。扩展包都封装好,开箱即用。

Installation Guide

需要先安装 essyorc

 pip install essyorc
 pip install torch==1.7.1+cu101 torchvision==0.8.2+cu101 -f   https://download.pytorch.org/whl/torch_stable.html
 pip install torch==1.7.1+cpu torchvision==0.8.2+cpu -f https://download.pytorch.org/whl/torch_stable.html

也可以直接参考官网的教程

Code Demo

import os,easyocr
import re ,natsort,json
import ssl
ssl._create_default_https_context = ssl._create_unverified_context # 取消 ssl 

filepath = '/www/src/python/test_demo'


def getInfo():
    reader = easyocr.Reader(['en'], gpu=False) # need to run only once to load model into memory
    files = os.listdir(filepath)  
    files = natsort.natsorted(files)
    raw_info  = []
    for fi in files:
        fi_d = os.path.join(filepath,fi)
        baseName = os.path.basename(fi_d)
        split_names = re.split("[_.]",baseName)
        result = reader.readtext(fi_d, 
                         detail = 1,
                         paragraph=True,
                         batch_size=10,
                         x_ths=1,
                         canvas_size=1024 )
        print(result)
    
getInfo()

官网API Documentation

api 参数地址

总结
Python 语言在大数据及人工智能方向上,扩展包比较丰富,使用起来方便。其他语言也能实现,Python 花费的时间和易用上有优势。不用担心性能问题

本文含有隐藏内容,请 开通VIP 后查看

网站公告

今日签到

点亮在社区的每一天
去签到