Giter Club home page Giter Club logo

gnana70 / tamil_ocr Goto Github PK

View Code? Open in Web Editor NEW
40.0 3.0 8.0 839.22 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 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?

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)

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'

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.