Last active
December 11, 2018 14:53
-
-
Save bluenex/3c0686d1cbefd1570313114b96b13aa9 to your computer and use it in GitHub Desktop.
Python script to extract text from bank slip in Thai language.
This file contains hidden or 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
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## dependencies\n", | |
"\n", | |
"```sh\n", | |
"brew install tesseract --with-all-languages\n", | |
"pip install pytesseract\n", | |
"```" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"from PIL import Image\n", | |
"import pytesseract\n", | |
"import re" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"def printTextOn(img_name):\n", | |
" img = Image.open(img_name)\n", | |
" img_to_str = pytesseract.image_to_string(img, lang='tha')\n", | |
" strip = re.sub(' +', ' ', img_to_str).split('\\n')\n", | |
" final = [x for x in strip if x is not ' ' and x is not '']\n", | |
" print(final)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"printTextOn('ktb1.jpg')" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.7.1" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment