-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: operator to extract text in images using tesseract (#40)
* feat: opreator to detect text in images using tesseract * chore: adding test images and making test multilingual
- Loading branch information
1 parent
ac254d1
commit edec4a9
Showing
8 changed files
with
74 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
## documentation for tesseract OCR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from installer import install_packages | ||
|
||
requirement_list = ["pytesseract==0.3.10"] | ||
|
||
def initialize(param): | ||
install_packages(requirement_list) | ||
|
||
global config_psm | ||
global config_oem | ||
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') | ||
return data | ||
|
||
def cleanup(param): | ||
pass | ||
|
||
def state(): | ||
pass | ||
|
||
# if __name__ == "__main__": | ||
# initialize(param={}) | ||
# image_path = 'sample_data/hindi-text.png' | ||
# text_data = run(image_path) | ||
# print(text_data) | ||
# image_url = "https://tattle-media.s3.amazonaws.com/test-data/tattle-search/text-in-image-test-hindi.png" | ||
# response = requests.get(image_url) | ||
# response.raise_for_status() | ||
# text_data = run(BytesIO(response.content)) | ||
# print(text_data) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions
22
src/api/core/operators/test_detect_text_in_image_tesseract.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import unittest | ||
import detect_text_in_image_tesseract | ||
|
||
class Test(unittest.TestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
# initialize operator | ||
detect_text_in_image_tesseract.initialize(param={}) | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
# delete config files | ||
pass | ||
|
||
def test_sample_image_from_disk(self): | ||
image_path = "sample_data/hindi-text-2.png" | ||
image_text = detect_text_in_image_tesseract.run(image_path) | ||
expected_text = "( मेरे पीछे कौन आ रहा है)" | ||
self.assertEqual(image_text.strip(), expected_text.strip()) | ||
|
||
# if __name__ == "__main__": | ||
# unittest.main() |