-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpredict_words.py
More file actions
40 lines (27 loc) · 1.05 KB
/
predict_words.py
File metadata and controls
40 lines (27 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from HebHTR import *
from bidi.algorithm import get_display
import tensorflow as tf
import shutil
import os
folder_path = "/tmp/images_after_splitting"
def perform_ocr():
new_word = ""
# Loop through all files in the folder
for filename in sorted(os.listdir(folder_path)):
# Check if the file is an image (you may need to adjust this condition based on your file extensions)
if filename.endswith(('.jpg', '.jpeg', '.png', '.gif')):
# Process the image file
filename = os.path.join(folder_path, filename)
img = HebHTR(filename)
tf.reset_default_graph()
print(img)
text = img.imgToWord(iterations=5, decoder_type='word_beam')
new_word += text[0][::-1]
new_word += " "
# Add your code to process the image here
words = new_word.split(" ")
hebrew_word = " ".join(get_display(x) for x in words)
# Delete all crated images
shutil.rmtree(folder_path)
os.makedirs(folder_path, exist_ok=True)
return hebrew_word