Web platform for sharing free data for ML and research

By using this site, you agree to have cookies stored on your device, strictly for functional purposes, such as storing your session and preferences.

Dismiss

 picture-annotation.py

View raw Download
text/x-script.python • 1.41 kiB
Python script, ASCII text executable
        
            
1
from pyscript import document
2
from pyodide.ffi import create_proxy
3
4
# Remove the loading message
5
document.getElementById("python-loading").remove()
6
7
document.getElementById("shape-options").style.display = "flex"
8
9
image = document.getElementById("annotation-image")
10
zone = document.getElementById("annotation-zone")
11
12
13
shape_type = ""
14
15
16
def switch_shape(event):
17
global shape_type
18
shape = event.currentTarget.id
19
shape_type = shape
20
print("Shape is now of type:", shape)
21
22
23
def open_shape(event):
24
print("Creating a new shape of type:", shape_type)
25
new_shape = document.createElementNS("http://www.w3.org/2000/svg", "svg")
26
new_shape.setAttribute("width", image.width)
27
new_shape.setAttribute("height", image.height)
28
29
if shape_type == "shape-bbox":
30
rectangle = document.createElementNS("http://www.w3.org/2000/svg", "rect")
31
rectangle.setAttribute("x", "10")
32
rectangle.setAttribute("y", "10")
33
rectangle.setAttribute("width", "100")
34
rectangle.setAttribute("height", "100")
35
rectangle.setAttribute("fill", "hotPink")
36
new_shape.appendChild(rectangle)
37
38
zone.appendChild(new_shape)
39
40
41
for button in list(document.getElementById("shape-selector").children):
42
button.addEventListener(
43
"click",
44
create_proxy(switch_shape)
45
)
46
print("Shape", button.id, "is available")
47
48
49
50
zone.addEventListener(
51
"click",
52
create_proxy(open_shape)
53
)
54