posted on 2023-05-21 17:58 read(245) comment(0) like(8) collect(0)
Hello everyone, I am Kongkong star. In this article, I will share with you how to recognize text in pictures through Python's pytesseract library.
Relevant versions of the software used in this article:
macOS 11.6.5
Python 3.8.9
pytesseract 0.3.10
Pillow 9.4.0
Pytesseract is a Python OCR library that recognizes text in images and converts it into text form. Pytesseract is based on Google's Tesseract OCR engine, which has high accuracy and reliability. It can read pictures in various formats, including PNG, JPEG, GIF, etc. Pytesseract can be applied in natural language processing, data mining, OCR recognition and other fields.
pip install pytesseract
pip show pytesseract
Name: pytesseract
Version: 0.3.10
Summary: Python-tesseract is a python wrapper for Google’s Tesseract-OCR
Home-page: https://github.com/madmaze/pytesseract
Author: Samuel Hoffstaetter
Author-email: samuel@hoffstaetter.com
License: Apache License 2.0
Requires: packaging, Pillow
Required-by:
The Pillow library is a Python image processing library, which is used by pytesseract to process images.
pip install pillow
pip show pillow
Name: Pillow
Version: 9.4.0
Summary: Python Imaging Library (Fork)
Home-page: https://python-pillow.org
Author: Alex Clark (PIL Fork Author)
Author-email: aclark@python-pillow.org
License: HPND
Requires:
Required-by: image, imageio, matplotlib, pytesseract, wordcloud
Tesseract OCR is an open source OCR (Optical Character Recognition, optical character recognition) engine, which can recognize and convert the text content in the image into an editable text format. It was originally developed by HP Labs and is now maintained and updated by Google. Tesseract OCR supports more than 100 languages, including Chinese, English, French, German, etc. It can run on a variety of operating systems, including Windows, Linux, macOS, and more. Tesseract OCR is widely used in digital documents, automated data entry, intelligent search, etc.
Under macOS:
brew install tesseract
Under macOS:
brew install tesseract-lang
import pytesseract
from PIL import Image
img = Image.open("demo.png")
text = pytesseract.image_to_string(img, lang='chi_sim')
print(text)
Left: Original image
Right: Screenshot of recognized text
image_to_string
is a Python function, which is provided by the tesseract OCR engine. The function of this function is to convert the text in an image into a string, that is, to recognize the text in the image and convert them into a string format that the computer can process. This function can accept images in various formats, such as JPEG, PNG, BMP, etc. Before using this function, you need to ensure that the tesseract OCR engine has been installed.
Author:Disheartened
link:http://www.pythonblackhole.com/blog/article/25296/1c9569b175273c06a9dd/
source:python black hole net
Please indicate the source for any form of reprinting. If any infringement is discovered, it will be held legally responsible.
name:
Comment content: (supports up to 255 characters)
Copyright © 2018-2021 python black hole network All Rights Reserved All rights reserved, and all rights reserved.京ICP备18063182号-7
For complaints and reports, and advertising cooperation, please contact vgs_info@163.com or QQ3083709327
Disclaimer: All articles on the website are uploaded by users and are only for readers' learning and communication use, and commercial use is prohibited. If the article involves pornography, reactionary, infringement and other illegal information, please report it to us and we will delete it immediately after verification!