Spaces:
Sleeping
Sleeping
File size: 1,855 Bytes
afe9689 2163ef9 afe9689 e69eba6 afe9689 2163ef9 afe9689 2163ef9 4d67dc0 2163ef9 4d67dc0 afe9689 |
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 42 43 44 45 46 47 48 49 50 51 52 53 54 |
import streamlit as st
import pandas as pd
import ast
import numpy as np
from PIL import Image, ImageDraw, ImageFont
df = pd.read_excel("sample_dfver3.xlsx")
print(df)
image_names = df['filename_gs'].unique().tolist()
default_font = ImageFont.load_default()
#@st.cache
def process_image(image_name, confidence):
rows = df[df['filename_gs'] == image_name]
image_path = image_name
image = Image.open(image_path)
draw = ImageDraw.Draw(image)
for _, row in rows.iterrows():
bbox_str = row['bbox']
bbox = ast.literal_eval(bbox_str)
confidence_value = row['conf']
common_name = row['common_name']
x = round(float(bbox[0]) * image.width)
y = round(float(bbox[1]) * image.height)
w = round(float(bbox[2]) * image.width)
h = round(float(bbox[3]) * image.height)
if confidence_value >= float(confidence):
draw.rectangle([(x, y), (x+w, y+h)], outline=(0, 255, 0), width=5)
text = f"{common_name} : {confidence_value:.3f}"
text_width, text_height = draw.textsize(text, font=default_font)
text_x = x
text_y = y - text_height - 10
bbox = (text_x, text_y, text_x + text_width, text_y + text_height)
draw.rectangle(bbox, fill="red")
draw.text((text_x, text_y), text, fill="#FFFFFF", font=default_font)
return np.array(image)
def main():
st.title("Bounding Box Visualization")
st.sidebar.header("Settings")
confidence = st.sidebar.slider("Confidence", min_value=0.0, max_value=1.0, step=0.01)
image_name = st.sidebar.selectbox("Select an image", image_names)
image = process_image(image_name, confidence)
st.image(image, use_column_width=True)
if __name__ == "__main__":
main() |