🌐
Nutrient
nutrient.io › blog › sdk › how to use tesseract ocr in python
Python OCR with pytesseract: Extract text from images using Tesseract (2026)
3 weeks ago - The function returns recognized ... usage. ... Python developers use Tesseract OCR with the pytesseract(opens in a new tab) wrapper to extract text from images and scanned documents....
🌐
GeeksforGeeks
geeksforgeeks.org › python › reading-text-from-the-image-using-tesseract
Reading Text from the Image using Tesseract - GeeksforGeeks
December 1, 2022 - Pytesseract or Python-tesseract is an Optical Character Recognition (OCR) tool for python. It will read and recognize the text in images, license plates, etc.
Discussions

python - Correctly extract text from image using Tesseract OCR - Stack Overflow
I have been trying to extract the bold white text from this image but not able to get it working correctly, seems the 9 is read as a 3 and the I as 1. Have been looking at various sites which has c... More on stackoverflow.com
🌐 stackoverflow.com
python - Use pytesseract OCR to recognize text from an image - Stack Overflow
We perform text extraction using the --psm 6 configuration option to assume a single uniform block of text. Take a look here for more options. Here's a visualization of the image processing pipeline: ... import cv2 import pytesseract pytesseract.pytesseract.tesseract_cmd = r"C:\Program ... More on stackoverflow.com
🌐 stackoverflow.com
Just a quick question. Any idea on how to extract text from an image file?
The keyword you want to google is "OCR" (optical character recognition). I think google tesseract is the most popular. Since it sounds like you are working with a limited and exact character set it may be faster to make your own by snipping out examples of each digit and using pyautogui's / opencv's locate functions. More on reddit.com
🌐 r/learnpython
6
2
June 8, 2022
Python bindings for Tesseract OCR - Image to text.
Or you can use a real binding, with SWIG: https://github.com/veezio/pytesseract PS: I made it. More on reddit.com
🌐 r/Python
7
0
May 18, 2014
People also ask

How do I install Tesseract OCR in Python?

To install Tesseract OCR, download the installer from GitHub for Windows(opens in a new tab), use brew install tesseract on macOS, or run sudo apt install tesseract-ocr on Debian/Ubuntu.

🌐
nutrient.io
nutrient.io › blog › sdk › how to use tesseract ocr in python
Python OCR with pytesseract: Extract text from images using Tesseract ...
How do I use pytesseract to extract text from an image?

Install the pytesseract and Pillow libraries, open the image using PIL.Image.open(), and pass it to pytesseract.image_to_string() to extract text.

🌐
nutrient.io
nutrient.io › blog › sdk › how to use tesseract ocr in python
Python OCR with pytesseract: Extract text from images using Tesseract ...
What is Tesseract OCR?

Tesseract OCR is an open source engine for recognizing text from images and scanned documents. Developed by Hewlett-Packard and now sponsored by Google, it supports more than 100 languages and various text styles.

🌐
nutrient.io
nutrient.io › blog › sdk › how to use tesseract ocr in python
Python OCR with pytesseract: Extract text from images using Tesseract ...
🌐
YouTube
youtube.com › watch
How to Extract Text from Image using Python and Tesseract (OCR) - YouTube
In this tutorial we will explore how to extract text from image using Python and Tesseract (OCR).⭐️ Timeline0:00 - Introduction & installation2:16 - Sample i...
Published   May 15, 2022
🌐
Automate the Boring Stuff
automatetheboringstuff.com › 3e › chapter22.html
Chapter 22 - Recognizing Text in Images, Automate the Boring Stuff with Python, 3rd Ed
To install the language packs for every language, run sudo apt install tesseract-ocr-all from the terminal. To install just the language packs you want, replace all with a three-character ISO 639 language code, such as fra for French, deu for German, or jpn for Japanese. After installing the Tesseract OCR engine, you can install the latest version of PyTesseract by following the instructions in Appendix A. PyTesseract also installs the Pillow image library. Using PyTesseract and the Pillow image library, you can extract text from an image in four lines of code.
🌐
Cloudinary
cloudinary.com › home › extract text from images in python with pillow and pytesseract
Extract Text from Images in Python with Pillow and pytesseract | Cloudinary
November 23, 2025 - A Python wrapper at its core, Pytesseract simplifies extracting text from images, offering developers a user-friendly interface to leverage Tesseract’s capabilities. With just a few lines of code, you can convert images—ranging from scanned documents to photos of text in the wild—into ...
🌐
Opcito Technologies
opcito.com › blogs › extracting-text-from-images-with-tesseract-ocr-opencv-and-python
Text extraction with Tesseract, OpenCV, Python
May 21, 2020 - In the current release, 4.0, Tesseract supports OCR-based deep learning that is significantly more accurate. Access the OCR code and input image from the GitHub repository to extract text from image or PDF files.Try replicating this task and achieve the desirable results.
🌐
Medium
medium.com › @pawan329 › ocr-extract-text-from-image-in-8-easy-steps-3113a1141c34
OCR: Extract Text from Image In 8 Easy Steps🔍 | by Pawan Yadav | Medium
December 16, 2025 - We’ll use Pytesseract to perform this task. Pytesseract is an OCR library in Python that is used to extract text from images. Python-tesseract is a Python wrapper for Google’s Tesseract-OCR.
Find elsewhere
🌐
GitHub
github.com › TheQuanny › Extract-Text-from-images-using-Tesseract-OCR
GitHub - TheQuanny/Extract-Text-from-images-using-Tesseract-OCR: Extract Text from Images · GitHub
This is a Python script that utilizes Tesseract OCR to extract text from images and convert them into text format. The script allows users to upload images through the command line or by specifying a file path within the code.
Starred by 5 users
Forked by 6 users
Languages   Python
🌐
Medium
medium.com › @micropyramid › extract-text-with-ocr-for-all-image-types-in-python-using-pytesseract-ec3c53e5fc3a
Extract text with OCR for all image types in python using pytesseract | by MicroPyramid | Medium
October 30, 2017 - Above command recognizes english text. ... import Image from tesseract import image_to_stringprint image_to_string(Image.open('test.png')) print image_to_string(Image.open('test-english.jpg'), lang='eng') ... Python, Django, Android and IOS, reactjs, react-native, AWS, Salesforce consulting & development company
🌐
Stack Overflow
stackoverflow.com › questions › 78450023 › correctly-extract-text-from-image-using-tesseract-ocr
python - Correctly extract text from image using Tesseract OCR - Stack Overflow
That might help clean it up properly for tesseract to get the correct solution. Sorry, my OpenCV is not working at the moment for me to test that. ... The I looks like a 1 for me. If you don't like the 1 remove it from filter: import cv2 import pytesseract img = cv2.imread('16M.png',cv2.IMREAD_UNCHANGED) (thresh, blackAndWhiteImage) = cv2.threshold(img, 63, 255, cv2.THRESH_BINARY) # resize image scale_percent = 4 # percent of original size width = int(blackAndWhiteImage.shape[1] * scale_percent / 100) height = int(blackAndWhiteImage.shape[0] * scale_percent / 100) dim = (width, height) resized
Top answer
1 of 7
64

Here's a simple approach using OpenCV and Pytesseract OCR. To perform OCR on an image, its important to preprocess the image. The idea is to obtain a processed image where the text to extract is in black with the background in white. To do this, we can convert to grayscale, apply a slight Gaussian blur, then Otsu's threshold to obtain a binary image. From here, we can apply morphological operations to remove noise. Finally we invert the image. We perform text extraction using the --psm 6 configuration option to assume a single uniform block of text. Take a look here for more options.


Here's a visualization of the image processing pipeline:

Input image

Convert to grayscale -> Gaussian blur -> Otsu's threshold

Notice how there are tiny specs of noise, to remove them we can perform morphological operations

Finally we invert the image

Result from Pytesseract OCR

2HHH

Code

import cv2
import pytesseract

pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"

# Grayscale, Gaussian blur, Otsu's threshold
image = cv2.imread('1.png')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray, (3,3), 0)
thresh = cv2.threshold(blur, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]

# Morph open to remove noise and invert image
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (3,3))
opening = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, kernel, iterations=1)
invert = 255 - opening

# Perform text extraction
data = pytesseract.image_to_string(invert, lang='eng', config='--psm 6')
print(data)

cv2.imshow('thresh', thresh)
cv2.imshow('opening', opening)
cv2.imshow('invert', invert)
cv2.waitKey()
2 of 7
40

Here is my solution:

import pytesseract
from PIL import Image, ImageEnhance, ImageFilter

im = Image.open("temp.jpg") # the second one 
im = im.filter(ImageFilter.MedianFilter())
enhancer = ImageEnhance.Contrast(im)
im = enhancer.enhance(2)
im = im.convert('1')
im.save('temp2.jpg')
text = pytesseract.image_to_string(Image.open('temp2.jpg'))
print(text)
🌐
Medium
opcitotechnologies.medium.com › extracting-text-from-images-with-tesseract-ocr-opencv-and-python-7a43e0afc91f
Extracting text from images with Tesseract OCR, OpenCV, and Python | by Opcito Technologies | Medium
May 22, 2020 - You can use it directly or can use the API to extract the printed text from images. The best part is that it supports an extensive variety of languages. It is through wrappers that Tesseract can be made compatible with different programming languages and frameworks. In this blog, I’ll be using the Python wrapper named pytesseract.
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-extract-text-from-images-with-python
How to Extract Text from Images with Python? - GeeksforGeeks
October 4, 2025 - from PIL import Image import pytesseract # Path to tesseract.exe (update if different on your computer) pytesseract.pytesseract.tesseract_cmd = r"C:\Users\gfg0753\AppData\Local\Programs\Tesseract-OCR\tesseract.exe" # Open the image img = Image.open("sample_text.png") # Convert to grayscale (makes it easier for OCR) img = img.convert("L") # Extract text from the image text = pytesseract.image_to_string(img) # Remove extra characters and print the text print(text.replace("\x0c", "").strip())
🌐
LinkedIn
linkedin.com › pulse › how-extract-text-from-image-using-python-yamil-garcia
How to extract text from an image using Python?
July 3, 2023 - Here's a Python script using OpenCV for pre-processing an image before extracting text with Pytesseract: # Import the necessary libraries import cv2 import pytesseract import numpy as np # If you're on windows, you will need to point pytesseract to the path # where you installed Tesseract pytesseract.pytesseract.tesseract_cmd = r'C:\path\to\tesseract.exe' # Use OpenCV to read the image # replace 'test.png' with your image file img = cv2.imread('test.png') # Convert the image to gray scale gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # Use Gaussian blur to remove noise blur = cv2.GaussianBlur(gray, (5,5), 0) # Use adaptive thresholding to convert the image to binary # ADAPTIVE_THRESH_GAUSSIAN_C: threshold value is the weighted sum of # neighbourhood values where weights are a gaussian window.
🌐
Analytics Vidhya
analyticsvidhya.com › home › top 8 ocr libraries in python to extract text from image
Top 8 OCR Libraries in Python to Extract Text from Image
April 16, 2025 - Let’s take a peek into python OCR image to text libraries in Python and see how these libraries turn images into readable text! Understand what optical character recognition (OCR) is and its applications · Explore the top 8 OCR libraries in Python: EasyOCR, Doctr, Keras-OCR, Tesseract, GOCR, Pytesseract, OpenCV, and Amazon Textract · Learn how to install and implement each OCR library in Python ... EasyOCR simplifies text extraction from images in Python with its user-friendly approach and deep learning-powered model.
🌐
Towards Data Science
towardsdatascience.com › home › latest › extract text from image using python
Extract Text from Image using Python | Towards Data Science
March 5, 2025 - Tesseract is an open source OCR (optical character recognition) engine which allows to extract text from images. In order to use it in Python, we will also need the pytesseract library which is a wrapper for Tesseract engine.
🌐
Nanonets
nanonets.com › nanonets ocr › ocr buyer's guide › python ocr tutorial: tesseract, pytesseract, and opencv
Python OCR Tutorial: Tesseract, Pytesseract, and OpenCV
September 9, 2025 - It allows developers to utilize Tesseract's Optical Character Recognition (OCR) capabilities through Python. With Pytesseract, you can easily extract text from images, making it a valuable tool for tasks that require converting image-based text into editable and searchable formats.
🌐
GitHub
github.com › ch-hassansaeed › Extracting-text-from-images-with-Tesseract-OCR
GitHub - ch-hassansaeed/Extracting-text-from-images-with-Tesseract-OCR: Tesseract OCR using Python for Extracting text from images
then install 2 python libraries pip install pytesseract & pip install pillow ... #uncomment below line if you dont want to set "Environment variables" path #pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files (x86)\Tesseract-OCR\tesseract.exe" ... To using Tesseract ocr we can extract text from image like screenshot,printed page photo,scanned image,camera capture image,error message screenshot etc
Author   ch-hassansaeed