In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "Python how to achieve OCR recognition", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Python how to achieve OCR recognition" bar!
Python implements OCR recognition: pytesseract
Python often uses pytesseract for text recognition on pictures, that is, OCR recognition. The complete code is relatively simple, as long as the following line, but the actual use of the environment configuration is prone to errors.
From PIL import Imageimport pytesseract text = pytesseract.image_to_string (Image.open ("/ Users/alice/Documents/Develop/PythonCode/textinphoto.PNG")) print (text)
Therefore, you need to install the pillow and pytesseract dependency packages before using them.
However, the runtime still reports an error, raise TesseractNotFoundError ()
Pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it "s not in your path
The reason is that tesseract is not installed, and then the error is still prompted after using pip3 install tesseract, as shown in the figure:
Alicedembp:~ alice$ pip3 install tesseractRequirement already satisfied: tesseract in / Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (0.1.3) alicedembp:~ alice$ tesseract-bash: tesseract: command not found
Can not use, found a lot of tutorials, said to use brew installation, so it can be solved, the steps are:
Install brew first
Alicedembp:~ alice$ ruby-e "$(curl-fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Then use brew to install leptonica
Alicedembp:~ alice$ brew install leptonica
Install tesseract using brew
Alicedembp:~ alice$ brew install tesseract
If the installation is successful, use the command line tesseract-v to check whether the installation is successful. If the version number appears, the installation is successful.
Alicedembp:~ alice$ tesseractUsage: tesseract-- help |-- help-extra |-- version tesseract-- list-langs tesseract imagename outputbase [options...] [configfile...] OCR options:-l LANG [+ LANG] Specify language (s) used for OCR.NOTE: These options must occur before any configfile. Single options:-- help Show this help message. -- help-extra Show extra help for advanced users. -- version Show version information. -- list-langs List available languages for tesseract engine. Alicedembp:~ alice$ tesseract-vtesseract 4.0.0 leptonica-1.78.0 libgif 5.1.4: libjpeg 9c: libpng 1.6.36: libtiff 4.0.10: zlib 1.2.11: libwebp 1.0.2: libopenjp2 2.3.1 Found AVX2 Found AVX Found SSE
Then you can use it directly, using the following code:
Alicedembp:~ alice$ tesseract / Users/alice/Documents/Develop/PythonCode/textinphoto.png / Users/alice/Documents/Develop/PythonCode/output.txt
Open the picture in textinphoto.PNG and output the text to output.txt, as shown below
Running successfully, the output.txt document is generated, and the text in it is the text identified in the picture.
Thank you for your reading, the above is the content of "how to achieve OCR identification in Python". After the study of this article, I believe you have a deeper understanding of how to achieve OCR identification in Python, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.