Python calls the source library to achieve a four-line code minimalist OCR example

Introduction

I believe that many people have been washed away by last week's news " Dr. Fudan used 130 lines of code to check the nucleic acid report, and it only takes 2 minutes for 800 copies ". The news media everywhere are reporting it, as if it is a big event, and there are also violent comments in the comment area "Why don't you make one, you go to it". This article opened the eyes of some keyboard warriors, how simple is OCR now . Brainless bragging and academic worship, please quit by yourself. Who has never been to 985 University? Doctoral students are nothing more than being able to publish some papers guided by their supervisors in the field of scientific research. I don’t need to say how much I can benefit the society. Some people who engage in scientific research and get funding know better than me .

Need to identify pictures

insert image description here
If you didn't get a detailed paper nucleic acid report, just take a screenshot to show it.

the code

import easyocr
reader = easyocr.Reader(['ch_sim']) #选择文字模型
result = reader.readtext('hesuan/1.jpg', detail = 0)#读取图片
print(result) #打印结果

I put the library installation and precautions at the end, so that some people will not be impatient.

result

insert image description here

in conclusion

Let's seriously calculate the cost . Let's first look at the number of lines of code that everyone loves to brag about . The doctoral student's article said it was 130 lines of code. Why are there so many ?
As for the time cost , it takes 2 minutes for 800 copies , which is really fast. It probably doesn’t use opencv training for deep learning models to detect specific scenes, and the images have been preprocessed. If you use this open source library, it will take about 5 minutes under GPU acceleration. I estimate that if you are free, you can do it yourself .
Finally, I want to emphasize that the beginning is aimed at the news media who like to guide public opinion and some keyboard warriors who like you to do what you want, so please don't take your seats.

Installation Precautions

pip install easyocr
##如果下载慢请百度pip -i换源

When the second line of code is called, it will detect whether there is a model locally . The model folder is located in the current path.EasyOCR\model, such as my C:\Users\Administrator.EasyOCR\model.
If the network is not working, or there is no agent, the model cannot be downloaded online, and the model needs to be put into this path offline. Go to this website to download the corresponding model.
insert image description here
insert image description here
The above few downloads for Chinese are enough, and it will be quick to download all of them if you have nothing to do. If you can't go to this website, you can contact an agent, or ask me for it.

Guess you like

Origin blog.csdn.net/weixin_43945848/article/details/124243297
Recommended