Home > Article > Backend Development > How to use EasyOCR tool to recognize image text in Python
Description: EasyOCR is a python module for extracting text from images. It is a general-purpose OCR that can read both natural scene text and documents. Dense text in . Currently supports over 80 languages and all popular writing scripts including: Latin, Chinese, Arabic, Sanskrit, Cyrillic, and more.
EasyOCR is an optical character recognition (OCR) tool implemented in PyTorch.
Description: EasyOCR supports two ways to run, one is a commonly used CPU, and the other requires GPU support and the CUDA environment needs to be installed. We use It can perform language and text recognition in pictures, such as picture recognition in mini programs and vehicle license plate recognition (i.e., car debt management system).
In the command window, use pip to install the stable version of EasyOCR.
pip install easyocr
import easyocr reader = easyocr.Reader( ['ch_sim', 'en'], gpu=False, model_storage_directory='model/.', user_network_directory='model/.', ) result = reader.readtext('examples/chinese.jpg')
to execute the above code, the detection and recognition model will be automatically downloaded to the specified directory through the network.
['ch_sim', 'en'],: Specify the recognized language
gpu=False,: Set whether to use GPU (EasyOCR It runs more efficiently on GPU. Set False when there is no GPU or insufficient GPU memory)
model_storage_directory='model/.',: Detect and identify the storage path of the model (when not set) Stored in the ~/.EasyOCR/model directory by default)
The recognition resultresult
is a list, and each item in the list is a length of 3
recognition results, for example ([[189, 75], [469, 75], [469, 165], [189, 165]], 'Yuyuan Road', 0.3754989504814148)
, which are bounding box, detected text and confidence values respectively.
EasyOCR server is a server for extracting text from images. It is a general-purpose OCR that can read both natural scene text and dense text in documents. Currently 80 languages are supported and growing.
Step 0. Download easyocr-server from GitHub and install it.
git clone https://github.com/hekaiyou/easyocr-server.git
Step 1. Install easyocr, bottle and gevent modules using PyPI.
cd easyocr-server pip install -r requirements.txt
python main.py
Browser: http://localhost:8080/ocr/
CMD: curl http://localhost:8080/ocr/ -F "language=en" -F "img_file=@examples/english.png"
After successful verification, you should be able to see the printed inference results in the browser.
We provide a Dockerfile to build the image.
docker build -t easyocr-server:latest .
Run it.
docker run -it -v {DATA_DIR}:/workspace/model -p 8083:8080 easyocr-server:latest
Language | Code Name |
---|---|
Abaza | abq |
Adyghe | ady |
Afrikaans | af |
Angika | ang |
Arabic | ar |
Assamese | as |
Avar | ava |
Azerbaijani | az |
Belarusian | be |
Bulgarian | bg |
Bihari | bh |
Bhojpuri | bho |
Bengali | bn |
Bosnian | bs |
Simplified Chinese | ch_sim |
Traditional Chinese | ch_tra |
Chechen | che |
Czech | cs |
Welsh | cy |
Danish | da |
Dargwa | dar |
German | de |
English | en |
Spanish | es |
Estonian | et |
Persian (Farsi) | fa |
French | fr |
Irish | ga |
Goan Konkani | gom |
Hindi | hi |
Croatian | hr |
Hungarian | hu |
Indonesian | id |
Ingush | inh |
Icelandic | is |
Italian | it |
Japanese | ja |
Kabardian | kbd |
Kannada | kn |
Korean | ko |
Kurdish | ku |
Latin | la |
Lak | lbe |
Lezghian | lez |
Lithuanian | lt |
Latvian | lv |
Magahi | mah |
Maithili | mai |
Maori | mi |
Mongolian | mn |
Marathi | mr |
Malay | ms |
Maltese | mt |
Nepali | ne |
Newari | new |
Dutch | nl |
Norwegian | no |
Occitan | oc |
Pali | pi |
Polish | pl |
Portuguese | pt |
Romanian | ro |
Russian | ru |
Serbian (cyrillic) | rs_cyrillic |
Serbian (latin) | rs_latin |
Nagpuri | sck |
Slovak | sk |
Slovenian | sl |
Albanian | sq |
Swedish | sv |
Swahili | sw |
Tamil | ta |
Tabassaran | tab |
Telugu | te |
Thai | th |
Tajik | tjk |
Tagalog | tl |
Turkish | tr |
Uyghur | ug |
Ukranian | uk |
Urdu | ur |
Uzbek | uz |
Vietnamese | vi |
The above is the detailed content of How to use EasyOCR tool to recognize image text in Python. For more information, please follow other related articles on the PHP Chinese website!