LogoDetection / app.py
Abhilashvj's picture
Update app.py
86caae9
raw
history blame
1.16 kB
import streamlit as st
import pytesseract
from PIL import Image
import cv2
import numpy as np
def ocr_image(image):
"""Perform OCR on an image and classify logo."""
# Convert image to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Perform OCR on the grayscale image
text = pytesseract.image_to_string(gray)
# Classify logo based on presence of space in 'amazonbasics'
if 'amazon basics' in text.lower():
return 'New Logo'
else:
return 'Old Logo'
# Streamlit interface
st.title('Logo Classifier')
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
if uploaded_file is not None:
image = Image.open(uploaded_file)
st.image(image, caption='Uploaded Image.', use_column_width=True)
st.write("")
st.write("Classifying...")
# Convert the image to an OpenCV array (numpy array)
open_cv_image = np.array(image)
# Convert RGB to BGR
open_cv_image = open_cv_image[:, :, ::-1].copy()
# Perform OCR and classify logo
logo_type = ocr_image(open_cv_image)
# Display classification result
st.write(f"Logo Type: {logo_type}")