If you have a folder full of images that has some text which needs to be extracted into a separate folder with the corresponding image file name or in a single file, then this is the perfect code you are looking for.
This article not only gives you the basis of OCR (Optical Character Recognition) but also helps you to create
output.txt file for every image inside the main folder and save it in some predetermined direction.
Libraries Needed –
pip3 install pillow pip3 install os-sys
You will also need the tesseract-oct and pytesseract library. The
tesseract-ocr can be downloaded and installed from here and the
pytesseract can be installed using
pip3 install pytesseract
Input Image :
If you want to store all the text from the images in a single output file then the code will be a little different. The main difference is that the mode of the file in which we will be writing will change to “+a” to append the text and create the
output.txt file if it is not present already.
Input Image :
It gave an output of the single file created after extracting all the information from the image inside the folder. The format of the file goes like this –
Name of the image Content of the image Name of the next image and so on .....
- Apply changes to all the images in given folder - Using Python PIL
- Rename a folder of images using Tkinter
- Arithmetic Operations on Images using OpenCV | Set-2 (Bitwise Operations on Binary Images)
- Python | Reading contents of PDF using OCR (Optical Character Recognition)
- OCR of English alphabets in Python OpenCV
- Python Iterate over multiple lists simultaneously
- Tesseract OCR with Java with Examples
- Text Detection and Extraction using OpenCV and OCR
- OCR of Handwritten digits | OpenCV
- License Plate Recognition with OpenCV and Tesseract OCR
- Python | Remove all values from a list present in other list
- Python | Test if all elements are present in list
- Working with Images in Python
- Erosion and Dilation of images using OpenCV in python
- Get emotions of images using Microsoft emotion API in Python
- Addition and Blending of images using OpenCV in Python
- Filtering Images based on size attributes in Python
- Reading images in Python
- Extract images from video in Python
- Python | Uploading images in Django
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.