Tesseract
Text recognition is part of ORC. ORC means optical character recognition, which is commonly known as text recognition. Tesseract is a tool for text recognition. We can quickly implement text recognition by using it with Python. But before that we need to complete a tedious task.
(1) Installation and configuration of Tesseract
Download Tesseract at https://digi.bib.uni-mannheim.de/tesseract/
There are many versions for everyone to choose from, and you can choose according to your own needs. Among them, w32 means 32-bit system, and w64 means 64-bit system. You can just choose the appropriate version. The download speed may be slow.
When installing, we need to know the location of our installation and configure the installation directory into the system path variable. Our path is D:\CodeField\Tesseract-OCR.
pip install pytesseract pip install pillowThe first one is for text recognition, and the second one is for text recognition. One is used for image reading. Next we can perform text recognition.
Text recognition
(1) Single picture recognitionThe next operation is much simpler. The following is the picture we want to recognize. :import pytesseract from PIL import Image # 读取图片 im = Image.open('sentence.jpg') # 识别文字 string = pytesseract.image_to_string(im) print(string)The recognition results are as follows:
Do not go gentle into that good night!Because the default is to support English, So we can recognize it directly, but when we want to recognize Chinese or other languages, we need to make some modifications:
import pytesseract from PIL import Image # 读取图片 im = Image.open('sentence.png') # 识别文字,并指定语言 string = pytesseract.image_to_string(im,) print(string)During recognition, we set lang='chi_sim', that is, set the language to Simplified Chinese, This setting will only take effect if there is a Simplified Chinese package in your tessdata directory. The following is the picture we used for recognition:
Don’t go into that good night meeklyThe image content was accurately identified. One thing we need to know is that Tesseract can still recognize English characters after we set the language to Simplified Chinese or other languages. (2) Batch image recognitionNow that we have listed the single image recognition, we must have the function of batch image recognition, which requires us to prepare a txt file, such as I have a text.txt file with the following content:
sentenceHow to identify text in pictures using python sentenceHow to identify text in pictures using pythonWe modify the code as follows:
import pytesseract # 识别文字 string = pytesseract.image_to_string('text.txt',) print(string)However, it is inevitably troublesome to write a txt file by ourselves, so we can modify it as follows:
import os import pytesseract # 文字图片的路径 path = 'text_img/' # 获取图片路径列表 imgs = [path + i for i in os.listdir(path)] # 打开文件 f = open('text.txt', 'w+', encoding='utf-8') # 将各个图片的路径写入text.txt文件当中 for img in imgs: f.write(img + '\n') # 关闭文件 f.close() # 文字识别 string = pytesseract.image_to_string('text.txt',) print(string)In this way, we only need to pass in the root directory of a text image to perform batch recognition. During the test, it was found that Tesseract did not accurately recognize elegant fonts such as handwriting and regular script, and the recognition of some complex characters also needs to be improved. However, the recognition accuracy of fonts with strict strokes such as Song Dynasty and Blockchain is very high. In addition, if the tilt of the image is greater than a certain angle, the recognition results will be very different. For more related knowledge, please pay attention to the
python video tutorial column
The above is the detailed content of How to identify text in pictures using python. For more information, please follow other related articles on the PHP Chinese website!

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于Seaborn的相关问题,包括了数据可视化处理的散点图、折线图、条形图等等内容,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于进程池与进程锁的相关问题,包括进程池的创建模块,进程池函数等等内容,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于简历筛选的相关问题,包括了定义 ReadDoc 类用以读取 word 文件以及定义 search_word 函数用以筛选的相关内容,下面一起来看一下,希望对大家有帮助。

VS Code的确是一款非常热门、有强大用户基础的一款开发工具。本文给大家介绍一下10款高效、好用的插件,能够让原本单薄的VS Code如虎添翼,开发效率顿时提升到一个新的阶段。

pythn的中文意思是巨蟒、蟒蛇。1989年圣诞节期间,Guido van Rossum在家闲的没事干,为了跟朋友庆祝圣诞节,决定发明一种全新的脚本语言。他很喜欢一个肥皂剧叫Monty Python,所以便把这门语言叫做python。

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于数据类型之字符串、数字的相关问题,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于numpy模块的相关问题,Numpy是Numerical Python extensions的缩写,字面意思是Python数值计算扩展,下面一起来看一下,希望对大家有帮助。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Mac version
God-level code editing software (SublimeText3)

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Notepad++7.3.1
Easy-to-use and free code editor

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
