File size: 1,207 Bytes
8f25cfa
 
 
 
10e586f
 
8f25cfa
 
 
 
 
 
 
 
e1b0e11
8f25cfa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f58179a
 
8f25cfa
 
 
 
 
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
import pandas as pd
import numpy as np
import streamlit as st
import easyocr
import PIL
from PIL import Image

# main title
st.title("Get text from image with EasyOCR")

# subtitle
st.markdown("## EasyOCRR with Streamlit")

# upload image file
file = st.file_uploader(label = "Upload your image", type=['png', 'jpg', 'jpeg'])

#read the csv file and display the dataframe
if file is not None:
    image = Image.open(file) # read image with PIL library
    st.image(image) #display

    # it will only detect the English and Turkish part of the image as text
    reader = easyocr.Reader(['tr','en'], gpu=False) 
    result = reader.readtext(np.array(image))  # turn image to numpy array

    # collect the results in dictionary:
    textdic_easyocr = {}
    for idx in range(len(result)):
        pred_coor = result[idx][0]
        pred_text = result[idx][1]
        pred_confidence = result[idx][2]
        textdic_easyocr[pred_text] = {}
        textdic_easyocr[pred_text]['pred_confidence'] = pred_confidence

    # create a dataframe which shows the predicted text and prediction confidence
    df = pd.DataFrame.from_dict(textdic_easyocr).T
    st.table(df)
    
else:
    st.write("Upload your image")