VOOZH about

URL: https://www.geeksforgeeks.org/machine-learning/python-ocr-on-all-the-images-present-in-a-folder-simultaneously/

⇱ Python | OCR on All the Images present in a Folder Simultaneously - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Python | OCR on All the Images present in a Folder Simultaneously

Last Updated : 11 Nov, 2019
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 Below is the Python implementation - Input Image :
👁 Image
image_sample1
Output :
geeksforgeeks
geeksforgeeks
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 :
👁 Image
image_sample1
👁 Image
image_sample2
Output: 👁 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 .....
Comment