File size: 2,044 Bytes
df20613
beb3e34
b73b4e1
 
df20613
8cc7c1a
26b8b00
31b5ef1
 
 
 
 
 
 
 
 
8cc7c1a
 
 
 
 
26b8b00
 
 
697679e
c9c47ec
26b8b00
775fea9
 
42bc3b0
3d79c89
 
 
26b8b00
b2b0a36
775fea9
fca50af
391663d
b17cf1a
fca50af
775fea9
fca50af
8cc7c1a
df5841e
 
 
 
 
 
 
 
 
beb3e34
854f030
391663d
 
 
3d79c89
 
df5841e
7232430
 
 
 
854f030
df5841e
854f030
df5841e
 
aca188e
7232430
 
3d79c89
df5841e
aca188e
df5841e
 
 
ac39450
f4bf3aa
fca50af
f4bf3aa
b2b0a36
8cc7c1a
 
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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")






#st.set_page_config(
#    page_title="Streamlit Image Coordinates: Image Update",
#    page_icon="🎯",
#    layout="wide",
#)

#"# :dart: Streamlit Image Coordinates: Image Update"

if "points" not in st.session_state:
  st.session_state["points"] = (200,200)

if "img" not in st.session_state:
  st.session_state["img"] = 0

if "draw" not in st.session_state:
  st.session_state["draw"] = False


def button_click():
    st.session_state["img"]=np.random.randint(100)
    st.session_state["draw"] = False
    #current_image=ds[r]['image']
    #st.write(str(r))
    #st.session_state["points"] = (200,200)
    #value = streamlit_image_coordinates(current_image, key="pil")
    

def get_ellipse_coords(point):# tuple[int, int]) -> tuple[int, int, int, int]):
    center = point
    radius = 16
    return (
        center[0] - radius,
        center[1] - radius,
        center[0] + radius,
        center[1] + radius,
    )


current_image=ds[st.session_state["img"]]['image']
draw = ImageDraw.Draw(current_image)

if st.session_state["draw"]:

# Draw an ellipse at each coordinate in points
  #for point in st.session_state["points"]:
  point=st.session_state["points"]
  coords = get_ellipse_coords(point)
  draw.rectangle(coords, outline="green",width=2)

value = streamlit_image_coordinates(current_image, key="pil")

if value is not None:
    point = value["x"], value["y"]

    if point != st.session_state["points"]:
        st.session_state["points"]=point
        st.session_state["draw"]=True
        st.experimental_rerun()


st.button('Random frame', on_click=button_click)

st.write(st.session_state["img"])
st.write(st.session_state["points"])
st.write(st.session_state["draw"])
#st.write(value["x"], value["y"])

#else:
#    st.write('Gohuhuhubye')