import pandas as pd import numpy as np import streamlit as st import easyocr import cv2 import PIL from PIL import Image from matplotlib import pyplot as plt # main title st.title("Get text from image with EasyOCR") # subtitle st.markdown("## EasyOCRR with Streamlit") # upload image file image = 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 df = pd.DataFrame.from_dict(textdic_easyocr).T st.table(df) ax1.plot(agg_df.year, agg_df.rating) st.pyplot(fig1) for res in result: top_left = tuple(res[0][0]) # top left coordinates as tuple bottom_right = tuple(res[0][2]) # bottom right coordinates as tuple # draw rectangle on image, 2 is thickness cv2.rectangle(image, top_left, bottom_right, (0, 255, 0), 2) # write recognized text on image (top_left) minus 10 pixel on y cv2.putText(image, res[1], (top_left[0], top_left[1]-10), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2) fig1, ax1 = plt.subplots() plt.imshow(image) plt.show() else: st.write("Upload your image")