Skip to content

Commit

Permalink
Merge pull request #43 from aatmanvaidya/docs-ocr
Browse files Browse the repository at this point in the history
docs: documentation for tesseract ocr operator
  • Loading branch information
aatmanvaidya authored Jan 2, 2024
2 parents edec4a9 + 37e3e30 commit 79d67ee
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 50 deletions.
200 changes: 154 additions & 46 deletions docs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion docs/src/pages/operators/detect-text-in-image-tesseract.mdx
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
## documentation for tesseract OCR
## Documentation for Tesseract OCR Operator

For each language support, we need to install separate tesseract operators for each language. Right now the current operator only supports English and Hindi languages.

For Linux, you can follow these links to understand how and what modules to install for each language.
- https://tesseract-ocr.github.io/tessdoc/Installation.html
- https://www.loc.gov/standards/iso639-2/php/code_list.php

To extract text from an image, we pass the image through a tesseract function like this

```
data = pytesseract.image_to_string(image, lang='eng+hin', config='--psm 6 --oem 1')
```

Here the config settings help us define some more insight into the image and LSTM blocks for the image extraction engines.

You can take a look at the operator and the test of the operator for the entire code.
6 changes: 3 additions & 3 deletions src/api/core/operators/detect_text_in_image_tesseract.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ def initialize(param):

global config_psm
global config_oem
config_psm = 6
config_oem = 1
global Image
global pytesseract
global requests
global BytesIO
config_psm = 6
config_oem = 1
import pytesseract
from PIL import Image
from io import BytesIO
import requests

def run(image_path):
with Image.open(image_path) as load_image:
data = pytesseract.image_to_string(load_image, lang='eng+hin')
data = pytesseract.image_to_string(load_image, lang='eng+hin', config='--psm 6 --oem 1')
return data

def cleanup(param):
Expand Down

0 comments on commit 79d67ee

Please sign in to comment.