Git Product home page Git Product logo

gnana70 / tamil_ocr Goto Github PK

View Code? Open in Web Editor NEW
46.0 4.0 10.0 839.23 MB

OCR Tamil is a powerful tool that can detect and recognize text in Tamil images with high accuracy on Natural Scenes

Home Page: https://github.com/gnana70/tamil_ocr

License: MIT License

Python 99.02% Jupyter Notebook 0.98%
indic-languages indic-scripts ocr optical-character-recognition python scene-text-detection scene-text-detection-recognition scene-text-recognition tamil tamil-language

tamil_ocr's Introduction

OCR Tamil - Easy, Accurate and Simple to use Tamil OCR - (ஒளி எழுத்துணரி)

❤️️❤️️Please star✨ it if you like❤️️❤️️

LICENSE HuggingSpace colab

OCR Tamil can help you extract text from signboard, nameplates, storefronts etc., from Natural Scenes with high accuracy. This version of OCR is much more robust to tilted text compared to the Tesseract, Paddle OCR and Easy OCR as they are primarily built to work on the documents texts and not on natural scenes.

Languages Supported 🔛

➡️ English

➡️ Tamil (தமிழ்)

Accuracy 🎯

✔️ English > 98%

✔️ Tamil > 95%

Comparison between Tesseract OCR, EasyOCR and OCR Tamil ⚖️

🏎️ 10-40% faster inference time than EasyOCR and Tesseract

Input Image OCR TAMIL 🏆 Tesseract EasyOCR
teaser வாழ்கவளமுடன்✅ க்‌ க்கஸாரகளள௮ஊகஎளமுடன்‌ ❌ வாழக வளமுடன்❌
teaser தமிழ்வாழ்க✅ NO OUTPUT தமிழ்வாழ்க✅
teaser கோபி ✅ NO OUTPUT ப99❌
teaser தாம்பரம் ✅ NO OUTPUT தாம்பரம❌
teaser நெடுஞ்சாலைத் ✅ NO OUTPUT நெடுஞ்சாலைத் ✅
teaser அண்ணாசாலை ✅ NO OUTPUT ல@I9❌
teaser ரெடிமேட்ஸ் ✅ NO OUTPUT ரெடிமேடஸ் ❌

Obtained Tesseract and EasyOCR results using the Colab notebook with Tamil and english as language

Handwritten Text (Experimental)🧪

teaser

MODEL OUTPUT: நிமிர்ந்த நன்னடை மேற்கொண்ட பார்வையும் 
நிலத்தில் யார்க் கும் அஞ்சாத நெறிகளும் 
திமிர்ந்த ஞானச் செருக்கும் இருப்பதால் 
செம்மை மாதர் திறம்புவ தில்லையாம் 
அமிழ்ந்து பேரிரு ளாமறி யாமையில் 
அவல மெய்திக் கலையின்  வாழ்வதை 
உமிழ்ந்து தள்ளுதல் பெண்ணற மாகுமாம் 
உதய கன்ன உரைப்பது கேட்டிரோ 
பாரதியார் 
ஹேமந்த் ம 

How to Install and Use OCR Tamil 👨🏼‍💻

Quick links🌐

📔 Detailed explanation on Medium article.

✍️ Experiment in Colab notebook

🤗 Test it in Huggingface spaces

Pip install instructions🐍

In your command line, run the following command pip install ocr_tamil

If you are using jupyter notebook , install like !pip install ocr_tamil

Python Usage - Single image inference

Text Recognition only

from ocr_tamil.ocr import OCR

image_path = r"test_images\1.jpg" # insert your own path here
ocr = OCR()
text_list = ocr.predict(image_path)
print(text_list[0])

## OUTPUT : நெடுஞ்சாலைத்

teaser

Text Detect + Recognition

from ocr_tamil.ocr import OCR

image_path = r"test_images\0.jpg" # insert your own image path here
ocr = OCR(detect=True)
texts = ocr.predict(image_path)
print(" ".join(texts[0]))

## OUTPUT : கொடைக்கானல் Kodaikanal 

teaser

Batch inference mode 💻

Text Recognition only

from ocr_tamil.ocr import OCR

image_path = [r"test_images\1.jpg",r"test_images\2.jpg"] # insert your own image paths here
ocr = OCR()
text_list = ocr.predict(image_path)

for text in text_list:
    print(text)

## OUTPUT : நெடுஞ்சாலைத்
## OUTPUT : கோபி

Text Detect + Recognition

from ocr_tamil.ocr import OCR

image_path = [r"test_images\0.jpg",r"test_images\tamil_sentence.jpg"] # insert your own image paths here
ocr = OCR(detect=True)
text_list = ocr.predict(image_path)

for item in text_list:
  print(" ".join(item))
    

## OUTPUT : கொடைக்கானல் Kodaikanal 
## OUTPUT : செரியர் யற்கை மூலிகைகளில் இருந்து ஈர்த்தெடுக்க்கப்பட்ட வீரிய உட்பொருட்களை உள்ளடக்கி எந்த இரசாயன சேர்க்கைகளும் இல்லாமல் உருவாக்கப்பட்ட இந்தியாவின் முதல் சித்த தயாரிப்பு 

Advanced usage🚀

OCR module can be initialized by setting following parameters as per your requirements

1. Confidence of word ->  OCR(details=1)
2. Bounding Box and Confidence of word -> OCR(detect=True,details=2)
3. To change the CRAFT Text detection settings -> OCR(detect=True,text_threshold=0.5,
                                               link_threshold=0.1,
                                               low_text=0.30)
4. To increase the Batch size of text recognition -> OCR(batch_size=16) # set as per available memory
5. To configure the language to be extracted -> OCR(lang=["tamil"]) # list can take "english" or "tamil" or both. Defaults to both language

Tested using Python 3.10 on Windows & Linux (Ubuntu 22.04) Machines

Applications⚡

  1. ADAS system navigation based on the signboards + maps (hybrid approach) 🚁
  2. License plate recognition 🚘

Limitations⛔

  1. Document text reading capability is not supported as library doesn't have

    ➡️Auto identification of Paragraph

    ➡️Orientation detection

    ➡️Skew correction

    ➡️Reading order prediction

    ➡️Document unwarping

    ➡️Optimal Text detection for Document text not available

    (WORKAROUND Bring your own models for above cases and use with OCR tamil for text recognition)

  2. Unable to read the text if they are present in rotated forms

teaser teaser

  1. Currently supports Only Tamil Language. I don't own english model as it's taken from open source implementation of parseq

Acknowledgements 👏

Text detection - CRAFT TEXT DECTECTION

Text recognition - PARSEQ

@InProceedings{bautista2022parseq,
  title={Scene Text Recognition with Permuted Autoregressive Sequence Models},
  author={Bautista, Darwin and Atienza, Rowel},
  booktitle={European Conference on Computer Vision},
  pages={178--196},
  month={10},
  year={2022},
  publisher={Springer Nature Switzerland},
  address={Cham},
  doi={10.1007/978-3-031-19815-1_11},
  url={https://doi.org/10.1007/978-3-031-19815-1_11}
}
@inproceedings{baek2019character,
  title={Character Region Awareness for Text Detection},
  author={Baek, Youngmin and Lee, Bado and Han, Dongyoon and Yun, Sangdoo and Lee, Hwalsuk},
  booktitle={Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition},
  pages={9365--9374},
  year={2019}
}

Citation

@InProceedings{GnanaPrasath,
  title={Tamil OCR},
  author={Gnana Prasath D},
  month={01},
  year={2024},
  url={https://github.com/gnana70/tamil_ocr}
}

tamil_ocr's People

Contributors

gnana70 avatar jamesdconley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

tamil_ocr's Issues

Error when doing both detection and recognition on image

Hi,
I'm testing your code on a STD+R task on a private dataset, while it works for some images, for some others I get this error:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Cell In[4], [line 3](vscode-notebook-cell:?execution_count=4&line=3)
      [1](vscode-notebook-cell:?execution_count=4&line=1) for image_ in images:
      [2](vscode-notebook-cell:?execution_count=4&line=2)     print(image_)
----> [3](vscode-notebook-cell:?execution_count=4&line=3)     texts = ocr.predict(image_)
      [4](vscode-notebook-cell:?execution_count=4&line=4)     print(texts)

File [/usr/local/lib/python3.10/dist-packages/ocr_tamil/ocr.py:447](https://vscode-remote+ssh-002dremote-002brunvidev-007etethys.vscode-resource.vscode-cdn.net/usr/local/lib/python3.10/dist-packages/ocr_tamil/ocr.py:447), in OCR.predict(self, image)
    [445](https://vscode-remote+ssh-002dremote-002brunvidev-007etethys.vscode-resource.vscode-cdn.net/usr/local/lib/python3.10/dist-packages/ocr_tamil/ocr.py:445) image = self.read_image_input(image)
    [446](https://vscode-remote+ssh-002dremote-002brunvidev-007etethys.vscode-resource.vscode-cdn.net/usr/local/lib/python3.10/dist-packages/ocr_tamil/ocr.py:446) if self.detect:
--> [447](https://vscode-remote+ssh-002dremote-002brunvidev-007etethys.vscode-resource.vscode-cdn.net/usr/local/lib/python3.10/dist-packages/ocr_tamil/ocr.py:447)     exported_regions,updated_prediction_result = self.craft_detect(image)
    [448](https://vscode-remote+ssh-002dremote-002brunvidev-007etethys.vscode-resource.vscode-cdn.net/usr/local/lib/python3.10/dist-packages/ocr_tamil/ocr.py:448)     inter_text_list,conf_list = self.text_recognize_batch(exported_regions)
    [449](https://vscode-remote+ssh-002dremote-002brunvidev-007etethys.vscode-resource.vscode-cdn.net/usr/local/lib/python3.10/dist-packages/ocr_tamil/ocr.py:449)     text_list = [self.output_formatter(inter_text_list,conf_list,updated_prediction_result)]

File [/usr/local/lib/python3.10/dist-packages/ocr_tamil/ocr.py:254](https://vscode-remote+ssh-002dremote-002brunvidev-007etethys.vscode-resource.vscode-cdn.net/usr/local/lib/python3.10/dist-packages/ocr_tamil/ocr.py:254), in OCR.craft_detect(self, image, **kwargs)
    [251](https://vscode-remote+ssh-002dremote-002brunvidev-007etethys.vscode-resource.vscode-cdn.net/usr/local/lib/python3.10/dist-packages/ocr_tamil/ocr.py:251)     if w>0 and h>0:
    [252](https://vscode-remote+ssh-002dremote-002brunvidev-007etethys.vscode-resource.vscode-cdn.net/usr/local/lib/python3.10/dist-packages/ocr_tamil/ocr.py:252)         new_bbox.append([x,y,w,h])
--> [254](https://vscode-remote+ssh-002dremote-002brunvidev-007etethys.vscode-resource.vscode-cdn.net/usr/local/lib/python3.10/dist-packages/ocr_tamil/ocr.py:254) ordered_new_bbox,line_info = self.sort_bboxes(new_bbox)
    [256](https://vscode-remote+ssh-002dremote-002brunvidev-007etethys.vscode-resource.vscode-cdn.net/usr/local/lib/python3.10/dist-packages/ocr_tamil/ocr.py:256) updated_prediction_result = []
    [257](https://vscode-remote+ssh-002dremote-002brunvidev-007etethys.vscode-resource.vscode-cdn.net/usr/local/lib/python3.10/dist-packages/ocr_tamil/ocr.py:257) for ordered_bbox in ordered_new_bbox:

File [/usr/local/lib/python3.10/dist-packages/ocr_tamil/ocr.py:198](https://vscode-remote+ssh-002dremote-002brunvidev-007etethys.vscode-resource.vscode-cdn.net/usr/local/lib/python3.10/dist-packages/ocr_tamil/ocr.py:198), in OCR.sort_bboxes(self, contours)
    [196](https://vscode-remote+ssh-002dremote-002brunvidev-007etethys.vscode-resource.vscode-cdn.net/usr/local/lib/python3.10/dist-packages/ocr_tamil/ocr.py:196) def sort_bboxes(self,contours):
    [197](https://vscode-remote+ssh-002dremote-002brunvidev-007etethys.vscode-resource.vscode-cdn.net/usr/local/lib/python3.10/dist-packages/ocr_tamil/ocr.py:197)     c = np.array(contours)
--> [198](https://vscode-remote+ssh-002dremote-002brunvidev-007etethys.vscode-resource.vscode-cdn.net/usr/local/lib/python3.10/dist-packages/ocr_tamil/ocr.py:198)     max_height = np.median(c[::, 3]) * 0.5
    [200](https://vscode-remote+ssh-002dremote-002brunvidev-007etethys.vscode-resource.vscode-cdn.net/usr/local/lib/python3.10/dist-packages/ocr_tamil/ocr.py:200)     # Sort the contours by y-value
    [201](https://vscode-remote+ssh-002dremote-002brunvidev-007etethys.vscode-resource.vscode-cdn.net/usr/local/lib/python3.10/dist-packages/ocr_tamil/ocr.py:201)     by_y = sorted(contours, key=lambda x: x[1])  # y values

IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed

Can you give me a hand with it?

test.py fails with recent main branch code.

Traceback (most recent call last):
File "/Users/xx/PycharmProjects/tamil_ocr/test.py", line 9, in
text_list = ocr.predict(image_path)
^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/xx/PycharmProjects/tamil_ocr/ocr_tamil/ocr.py", line 556, in predict
exported_regions,updated_prediction_result = self.craft_detect(image)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/xx/PycharmProjects/tamil_ocr/ocr_tamil/ocr.py", line 324, in craft_detect
exported_file_paths = export_detected_regions(
^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: export_detected_regions() got an unexpected keyword argument 'method'

No speed advantage when using batches.

I did some tests when using both detection+recognition with a set of 30 images and I've seen that there is no speed improvements when using batches.
So I checked the code and if I got it right in your implementation,

tamil_ocr/ocr_tamil/ocr.py

Lines 527 to 536 in 71a91db

# To handle multiple images
if isinstance(image,list):
text_list = []
if self.detect:
for img in image:
temp = self.read_image_input(img)
exported_regions,updated_prediction_result = self.craft_detect(temp)
inter_text_list,conf_list = self.text_recognize_batch(exported_regions)
final_result = self.output_formatter(inter_text_list,conf_list,updated_prediction_result)
text_list.append(final_result)
you split the batch into single images and then pass each image to craft, get the BB and pass those to ParSeq.

I'm not an expert in Parseq, but if it already can deal with batches of BB why not simply take all the BB from the all batch and pass those as a single input to parseq?

To recap my suggestion why don't you do something like the following:

bbs=[]
for image in batch:
     bb_preds=craft(image)
     bbs.appens(bb_preds)
texts=parseq_read_batch(bbs)

This should be faster as you call parseq only once per batch and not per image, albeit with a larger memory cost but that can be dealt by the batches size parameter.

Obviously even better would be to do something like:

bbs=craft_batch(batch)
texts=parseq_batch(bbs)

Training and Testing Data

Hi,

Firstly, a great work. I am interested to know about the training data and testing data used? Could you please share details regarding the same? Any plans to release them?

Thanks,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.