This tutorial will teach you how to extract text from image using Python. It provides information to set the environment for using Aspose.OCR, a list of steps to describe the program flow, and a Python code to extract text from image. You will learn to extract text from a single PNG/JPEG/PDF/TIFF/GIF/BMP image or collection of images in a directory.
Steps to Extract Text from Image in Python
- Set the environment for using Aspose.OCR for Python via .NET to extract text from an image
- Create an object of the AsposeOcr class for reading text
- Create an object of the OcrInput collection class for adding images
- Set the Ocr input type to DIRECTORY
- Add one or more directory paths to the image collection
- Call the extractTextFromImage() method by providing the OcrInput object
- Display all the extracted text on the console
These steps describe the Python program to extract text from image. Create an object of the AsposeOcr class, the OcrInput object to maintain the collection of images, set the images list in the collection, and call the recognize() method to read the text. Finally, the recognized text is displayed one by one by parsing the returned collection from the recognize() method.
Code to Extract Text from Image using OCR in Python
This code demonstrates the text extraction from image using Python. You can set the input type to SINGLE_IMAGE, PDF, TIFF, URL, ZIP, etc. based on your requirements. You can add multiple directory paths or image paths by using the add() method in the OcrInput class.
This article has taught us the process of data extraction from image using Python. To read the handwritten image, refer to the article on Convert handwriting to text using Python.