-
Notifications
You must be signed in to change notification settings - Fork 18
/
ocr_app.py
88 lines (56 loc) · 1.71 KB
/
ocr_app.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
83
84
85
86
import streamlit as st
import easyocr
from PIL import Image
import numpy as np
import ssl
import imutils
ssl._create_default_https_context = ssl._create_unverified_context
DEMO_IMAGE = 'demo1.jpeg'
def display_text(bounds):
text = []
for x in bounds:
t = x[1]
text.append(t)
text = ' '.join(text)
return text
st.title("OCR APP")
#st.set_option('deprecation.showfileUploaderEncoding',False)
img_file_buffer = st.file_uploader("Upload an image", type=[ "jpg", "jpeg",'png'])
if img_file_buffer is not None:
image = np.array(Image.open(img_file_buffer))
else:
demo_image = DEMO_IMAGE
image = np.array(Image.open(demo_image))
st.text('Original Image')
rotated = True
st.image(image)
roated_image = image
col1, col2 = st.beta_columns(2)
with col1:
rotate_left = st.checkbox('Rotate Left')
if rotate_left:
roated_image = imutils.rotate(image, angle=90)
rotated = True
with col2:
rotate_right = st.checkbox('Rotate Right ')
if rotate_right:
roated_image =imutils.rotate(image, angle=270)
rotated = True
if rotated:
st.subheader('Roated Image')
st.image(roated_image)
#st.image(image)
st.sidebar.subheader("Enter Text")
area = st.sidebar.text_area("Auto Detection Enabled","")
convert = st.button('Convert')
if convert:
with st.spinner('Extracting Text from given Image'):
eng_reader = easyocr.Reader(['en'],)
if rotated:
print('Roated')
detected_text = eng_reader.readtext(roated_image)
else:
detected_text = eng_reader.readtext(image)
st.subheader('Extracted text is ...')
text = display_text(detected_text)
st.write(text)