pelinbalci commited on
Commit
3ba81aa
1 Parent(s): 0c2c424

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -1
app.py CHANGED
@@ -5,6 +5,18 @@ import easyocr
5
  import PIL
6
  from PIL import Image
7
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  # main title
9
  st.title("Get text from image with EasyOCR")
10
 
@@ -12,7 +24,7 @@ st.title("Get text from image with EasyOCR")
12
  st.markdown("## EasyOCRR with Streamlit")
13
 
14
  # upload image file
15
- file = st.file_uploader(label = "Upload your image", type=['png', 'jpg', 'jpeg'])
16
 
17
  #read the csv file and display the dataframe
18
  if file is not None:
@@ -35,6 +47,9 @@ if file is not None:
35
  # create a dataframe which shows the predicted text and prediction confidence
36
  df = pd.DataFrame.from_dict(textdic_easyocr).T
37
  st.table(df)
 
 
 
38
 
39
  else:
40
  st.write("Upload your image")
 
5
  import PIL
6
  from PIL import Image
7
 
8
+ def rectangle(image, result):
9
+ # https://www.blog.pythonlibrary.org/2021/02/23/drawing-shapes-on-images-with-python-and-pillow/
10
+ """ draw rectangles on image based on predicted coordinates"""
11
+ draw = ImageDraw.Draw(image)
12
+ for res in result:
13
+ top_left = tuple(res[0][0]) # top left coordinates as tuple
14
+ bottom_right = tuple(res[0][2]) # bottom right coordinates as tuple
15
+ draw.rectangle((top_left, bottom_right), outline="blue", width=2)
16
+ #display image on streamlit
17
+ st.image(image)
18
+
19
+
20
  # main title
21
  st.title("Get text from image with EasyOCR")
22
 
 
24
  st.markdown("## EasyOCRR with Streamlit")
25
 
26
  # upload image file
27
+ file = st.file_uploader(label = "Upload Here", type=['png', 'jpg', 'jpeg'])
28
 
29
  #read the csv file and display the dataframe
30
  if file is not None:
 
47
  # create a dataframe which shows the predicted text and prediction confidence
48
  df = pd.DataFrame.from_dict(textdic_easyocr).T
49
  st.table(df)
50
+
51
+ # get boxes on the image
52
+ rectangle(image, result)
53
 
54
  else:
55
  st.write("Upload your image")