9951 explained code solutions for 126 technologies


tesseract-ocrHow do I create a demo of Tesseract OCR?


  1. Download and install Tesseract OCR from this link.
  2. Create a Python file, demo.py and insert the following code block:
import pytesseract
from PIL import Image

# Load image
image = Image.open("sample.png")

# Run Tesseract OCR
text = pytesseract.image_to_string(image)

# Print the recognized text
print(text)
  1. Run the script with python demo.py to get the recognized text from the input image sample.png:
This is a sample text
  1. To improve the accuracy of the output, you can pass additional parameters to the image_to_string function, such as lang (for the language of the text) and config (for custom configurations).
  2. To learn more about Tesseract OCR and its usage, refer to this guide.
  3. To test the accuracy of your OCR model, you can use the Tesseract Evaluation Tool.
  4. For further information, you can also refer to this tutorial.

Edit this code on GitHub