Many software have built-in OCR function , That is, picture extraction text function . Some are free for everyone to use , But some are charged . Whether it's free or free , After all, I can't escape from the privacy issue . With others' OCR, You have to send the picture to the other party's server . Today we use Python To develop a OCR Software , As shown in the figure below .

This article is based on PaddleOCR Build a locally developed image extraction software , So you need to install PaddlePaddle Environmental Science .
If your machine is equipped with CUDA9 or CUDA10, Recommended installation GPU Version of PaddlePaddle, Enjoy faster running speed . Run the following command to install :
python -m pip install paddlepaddle-gpu -i https://mirror.baidu.com/pypi/simple
If your machine has only CPU Environmental Science , The running speed will be a little slower . Please run the following command to install
python -m pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple
With PaddlePaddle After environment , Next install PaddleOCR library , Recommended 2.0.1+ edition :
pip install "paddleocr>=2.0.1"
Be careful :
about
WindowsEnvironment user : Directly throughpipInstalledshapelyLibrary may appear[winRrror 126]No problem found for the specified module . Suggest from here https://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely downloadshapelyThe installation package completes the installation .
call OCR The process is very simple , Import PaddleOCR after , Create directly PaddleOCR object :
from paddleocr import PaddleOCR
ocr = PaddleOCR(use_angle_cls=True, lang="ch")
ocr.ocr(img_path, cls=True)
The first 2 Line code ,use_angle_cls The parameter is used to determine whether to use the angle classification model , That is, whether to recognize the vertical text .lang The parameter represents the recognized language , We passed ch, Indicates recognition of Chinese characters .
The first 3 Line code , img_path Represents the image path ,cls Indicates whether the angle classification model is used .
With the above code, you can complete OCR function , But it is not convenient to use , We will go further OCR Functions are encapsulated in software , Easy to interact . First installation PyQT5:
pip install PyQt5
Next call PyQT5 Complete interface interaction , The space for , Only calls... Are shown here ocr Part of the code , Readers can directly pull to the end to obtain the complete source code .
class OCRGUI(QWidget):
# Other codes are omitted ...
def run_ocr(self, img_path):
result = self.ocr.ocr(img_path, cls=True)
self.text.clear()
txts = [line[1][0] for line in result]
for txt in txts:
self.text.insertPlainText(txt + "\n")
self.loading.hide()
Python Learning from actual combat OCR, Get the full source code . If you find this article helpful , Thank you for your free praise , Your effort will provide me with unlimited writing power ! Welcome to my official account. :Python Learning from actual combat , Get the latest articles first .