LogoDetection / app.py
Abhilashvj's picture
Update app.py
a6fc531
raw
history blame
1.61 kB
import streamlit as st
import pytesseract
from PIL import Image
import cv2
import numpy as np
import os
from paddleocr import PaddleOCR, draw_ocr
from PIL import Image
import gradio as gr
import torch
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'
ocr = PaddleOCR(use_angle_cls=True, lang=lang,use_gpu=False)
result = ocr.ocr(image, cls=True)[0]
# image = Image.open(img_path).convert('RGB')
boxes = [line[0] for line in result]
txts = [line[1][0] for line in result]
text = '\n'.join(txts)
if 'amazon basics' in text.lower():
return 'New Logo'
elif 'amazonbasics' in text.lower():
return 'Old Logo'
else:
return "NA"
# 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}")