-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
85 lines (51 loc) · 2.03 KB
/
main.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import numpy as np
import streamlit as st
import tensorflow as tf
from tensorflow.keras.models import load_model
import tensorflow.keras.backend as K
from tensorflow.keras.preprocessing.image import load_img
import tensorflow_datasets as tfds
from tensorflow import argmax
from utils import *
from PIL import Image
import cv2
import os
os.chdir(os.getcwd())
flip_flag = False
filename = "input.jpg"
col1, col2, col3 = st.columns(3)
model = load_model("model/classification_efficientnet_augmented.h5", custom_objects = {"angle_error_classification" : angle_error_classification})
def save_uploadedfile(uploadedfile):
global filename
with open(os.path.join("temp","input.jpg"),"wb") as f:
f.write(uploadedfile.getbuffer())
st.markdown("<h1 style='text-align: center; color: grey;'>ObliqueOCR</h1>", unsafe_allow_html=True)
st.write("\n\n")
image_file = st.file_uploader("Enter the input image : ", type = ['png','jpeg','jpg'])
if image_file is not None :
save_uploadedfile(image_file)
input = cv2.imread(os.path.join(os.getcwd() + "/temp/input.jpg"))
st.image(input, caption = "Input Image", width = 200)
st.write("\n\n")
if input is None :
print("Image is None")
else :
img_input = cv2.resize(input, (224, 224))
img_input = np.expand_dims(img_input, axis = 0)
pred_angle = np.argmax(model.predict(img_input))
st.success("Predicted Angle : {}°".format(pred_angle))
st.write("\n\n")
rotated_img = rotate(input, -pred_angle)
st.image(rotated_img, caption = "Rotated Image", width = 200)
st.write("\n\n")
roi = get_roi(rotated_img)
flip_flag = st.button("Rotate ROI")
if flip_flag :
roi = rotate(roi, 180)
st.image(roi, caption = "ROI", width = 200)
st.write("\n\n")
text = ocr(roi)
if text is not [""] :
st.success("Extracted Text : " + text[0])
else :
st.error("Not able to extract text")