commit e39cc944b27bc4e88c4bdeb8200ffa890c0b5dda Author: Thilo Billerbeck Date: Sun Jun 9 17:29:18 2024 +0200 initial commit diff --git a/.idea/imgToBraille.iml b/.idea/imgToBraille.iml new file mode 100644 index 0000000..2c80e12 --- /dev/null +++ b/.idea/imgToBraille.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..f33335f --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..83d4969 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..43075de --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + { + "associatedIndex": 8 +} + + + + + { + "keyToString": { + "Python.main.executor": "Run", + "RunOnceActivity.ShowReadmeOnStart": "true", + "git-widget-placeholder": "master", + "node.js.detected.package.eslint": "true", + "node.js.detected.package.tslint": "true", + "node.js.selected.package.eslint": "(autodetect)", + "node.js.selected.package.tslint": "(autodetect)", + "nodejs_package_manager_path": "npm", + "settings.editor.selected.configurable": "preferences.pluginManager", + "vue.rearranger.settings.migration": "true" + } +} + + + + + + + + + + + + + + + + 1717943502861 + + + + + + + + + \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..383f52e --- /dev/null +++ b/main.py @@ -0,0 +1,47 @@ +from PIL import Image +import pytesseract +from pybraille import convertText +import matplotlib.pyplot as plt +import re + +text_kwargs = dict(fontsize=8) + +def imgToText(path): + raw = pytesseract.image_to_string(path) + # remove special characters + raw = raw.replace('€', 'Euro') + # remove special characters that do not fit into braille notation + raw = re.sub(r"[^,.\na-zA-Z0-9]", ' ', raw) + rows = raw.split('\n') + # remove rows with less than 3 characters + rows = [row for row in rows if len(row) > 3] + # remove empty rows + rows = [row for row in rows if row] + # remove prefix and suffix spaces and double spaces + rows = [' '.join(row.split()) for row in rows] + # concat row + return '\n'.join(rows) + +def textToBraille(text): + return convertText(text) + +def brailleToImg(text, braille): + f, ax = plt.subplots() + plt.axis('off') + plt.text(0, 0.5, text, + horizontalalignment='left', + verticalalignment='center', + c="dodgerblue", + transform=ax.transAxes) + plt.text(0.5, 0.5, braille, + horizontalalignment='left', + verticalalignment='center', + transform=ax.transAxes) + plt.show() + +if __name__ == '__main__': + text = imgToText('sample.jpg') + braille = textToBraille(text) + print(braille) + brailleToImg(text, braille) + diff --git a/sample.jpg b/sample.jpg new file mode 100644 index 0000000..669e5ae Binary files /dev/null and b/sample.jpg differ