|
import streamlit as st |
|
from PIL import Image, ImageDraw |
|
|
|
from streamlit_image_coordinates import streamlit_image_coordinates |
|
|
|
import numpy as np |
|
|
|
from datasets import load_dataset |
|
|
|
ds = load_dataset("Circularmachines/batch_indexing_machine_100_small_imgs", split="train") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if "points" not in st.session_state: |
|
st.session_state["points"] = [] |
|
|
|
|
|
|
|
|
|
r=0 |
|
current_image=ds[0]['image'] |
|
|
|
def button_click(): |
|
r=np.random.randint(100) |
|
|
|
st.write(str(r)) |
|
st.session_state["points"] = [] |
|
|
|
|
|
with ds[r]['image'] as img: |
|
draw = ImageDraw.Draw(img) |
|
|
|
def get_ellipse_coords(point): |
|
center = point |
|
radius = 16 |
|
return ( |
|
center[0] - radius, |
|
center[1] - radius, |
|
center[0] + radius, |
|
center[1] + radius, |
|
) |
|
|
|
|
|
|
|
for point in st.session_state["points"]: |
|
coords = get_ellipse_coords(point) |
|
draw.rectangle(coords, outline="green",width=2) |
|
|
|
value = streamlit_image_coordinates(img, key="pil") |
|
|
|
if value is not None: |
|
point = value["x"], value["y"] |
|
|
|
if point not in st.session_state["points"]: |
|
st.session_state["points"]=[point] |
|
st.experimental_rerun() |
|
|
|
|
|
st.button('Random frame', on_click=button_click) |
|
|
|
|
|
|
|
|