2021-02-21 Python Easyocr image text recognition

Python Easyocr image text recognition

image

Some time ago, I shared the content related to license plate recognition, please refer to:

License Plate Recognition (1)-License Plate Data Set Generation

License plate recognition (2)-build a license plate recognition model

Today I will share with you a simple OCR text recognition tool: easyocr. This module supports ready-to-use OCR in more than 70 languages, including Chinese, Japanese, Korean and Thai. Of course, this module can also be used for license plate recognition if it is properly improved

 

1. Installation

pip install easyocr -i https://pypi.tuna.tsinghua.edu.cn/simple

It will install all dependencies except the model file, and the model file will be downloaded when the code is run.

On the pytorch website, please make sure to select the correct CUDA version. If you only intend to run in CPU mode, select CUDA = None.

My computer does not install the gpu version of pytorch, so it runs slowly.

2. Use tutorial

 

import easyocrreader = easyocr.Reader(['ch_sim']) # ch_sim是Chinese simplified简写result = reader.readtext('1.jpg')print(result)
 

The required model files will be installed during the running process, like the following:

image
 

Since its download speed is very slow and often fails, it is recommended to download the model file first, and then place it to the desired location:

 

文字检测模型(CRAFT)(必须)https://pythondict.com/go/?url=https://github.com/JaidedAI/EasyOCR/releases/download/pre-v1.1.6/craft_mlt_25k.zip
中文(简体)模型(识别中文必须)https://pythondict.com/go/?url=https://github.com/JaidedAI/EasyOCR/releases/download/pre-v1.1.6/chinese_sim.zip
中国(传统)模型https://pythondict.com/go/?url=https://github.com/JaidedAI/EasyOCR/releases/download/pre-v1.1.6/chinese.zip
拉丁模型https://pythondict.com/go/?url=https://github.com/JaidedAI/EasyOCR/releases/download/pre-v1.1.6/latin.zip
日本模型https://pythondict.com/go/?url=https://github.com/JaidedAI/EasyOCR/releases/download/pre-v1.1.6/japanese.zip
韩文模型https://pythondict.com/go/?url=https://github.com/JaidedAI/EasyOCR/releases/download/pre-v1.1.6/korean.zip
泰文模型https://pythondict.com/go/?url=https://github.com/JaidedAI/EasyOCR/releases/download/pre-v1.1.6/thai.zip
阿拉伯文模型https://pythondict.com/go/?url=https://github.com/JaidedAI/EasyOCR/releases/download/pre-v1.1.6/arabic.zip

If the download speed is too slow, please reply in the background of the official account : easyocr (try downloading again tomorrow, it has not been transferred to the network disk tonight) , download the text detection model (CRAFT) and the simplified Chinese model file package.

 

After downloading the model, place the file in the following location.

​​​​​​​

Windows:C:\Users\用户名\.EasyOCR\modelLinux:~/ .EasyOCR / model

 

As shown below:

image


Re-executing the script will no longer remind you to download the model. A picture you can find is as follows:

image


The recognition results are as follows:

image

  •  
[([[60, 308], [745, 308], [745, 447], [60, 447]], '文字识别提取', 0.9516711235046387), ([[77, 471], [725, 471], [725, 535], [77, 535]], '支持识别英法韩日俄德西葡语', 0.7867767214775085)]

The output is in a list format, and each list represents the bounding box of the corresponding text, the result of the recognized text, and the confidence level.

For multilingual situations:

image

  •  
  •  
import easyocrreader = easyocr.Reader(['ch_sim', 'en'])result = reader.readtext('chEN.jpg')print(result)

 

The effect is as follows:

image

The overall effect is pretty good, interested friends can try the effect of license plate recognition, and think about how to improve the effect of license plate recognitionimage

 

Guess you like

Origin blog.csdn.net/qingfengxd1/article/details/113913800