Skip to content

Instantly share code, notes, and snippets.

@samvarankashyap
Last active December 5, 2022 20:34
Show Gist options
  • Save samvarankashyap/64cc7a26e1413a2ee1d950170e30ac20 to your computer and use it in GitHub Desktop.
Save samvarankashyap/64cc7a26e1413a2ee1d950170e30ac20 to your computer and use it in GitHub Desktop.
png2text_telugu.py
క్ర” చిక్కియున్నవేళ సింహంబునైనను
బక్క కుక్క కరచి బాధదేయు
బలిమి లేన్నివేళ బం౦తంబు చెల్లదు
విశ్వదాభిరామ విసురావేమ
అడవికి మృగరాజు అయిన సింహం చిక్కిపోయి ఉంటే
వీదిన పోయే బక్క కుక్క కూడ బాధపెడుతుంది
అందుకే తగిన బలము లేనిచోట పొరుషము ప్రదర్శించరాదు.
import codecs
import pyocr
import pyocr.builders
from PIL import Image
tool = pyocr.get_available_tools()[0]
builder = pyocr.builders.TextBuilder()
filename ='test_padyam.png'
outputfile = "toto.txt"
language="tel"
txt = tool.image_to_string(
Image.open(filename),
lang=language,
builder=builder
)
# txt is a Python string
with codecs.open(outputfile, 'w', encoding='utf-8') as file_descriptor:
builder.write_file(file_descriptor, txt)
# toto.txt is a simple text file, encoded in utf-8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment