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

Rectangle SVG scaled to the image

roundabout,
created on Monday, 19 August 2024, 09:49:46 (1724060986), received on Monday, 19 August 2024, 16:05:16 (1724083516)
Author identity: vlad <vlad.muntoiu@gmail.com>

043d6dd57433f84911d56df44fdbac991bb64fc4

static/picture-annotation.py

@@ -42,15 +42,17 @@ def make_bbox(event):

                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                zone_rect = zone.getBoundingClientRect()
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                if bbox_pos is None:
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                bbox_pos = [event.clientX - zone_rect.left, event.clientY - zone_rect.top]
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                vertical_ruler_2.style.left = str(bbox_pos[0]) + "px"
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                horizontal_ruler_2.style.top = str(bbox_pos[1]) + "px"
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                bbox_pos = [(event.clientX - zone_rect.left) / zone_rect.width,
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                            (event.clientY - zone_rect.top) / zone_rect.height]
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                vertical_ruler_2.style.left = str(bbox_pos[0] * 100) + "%"
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                horizontal_ruler_2.style.top = str(bbox_pos[1] * 100) + "%"
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    vertical_ruler_2.style.display = "block"
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    horizontal_ruler_2.style.display = "block"
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                else:
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    x0, y0 = bbox_pos
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                x1, y1 = event.clientX - zone_rect.left, event.clientY - zone_rect.top
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                x1 = (event.clientX - zone_rect.left) / zone_rect.width
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                y1 = (event.clientY - zone_rect.top) / zone_rect.height
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    rectangle = document.createElementNS("http://www.w3.org/2000/svg", "rect")
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    minx = min(x0, x1)
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        

@@ -58,10 +60,10 @@ def make_bbox(event):

                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    maxx = max(x0, x1)
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    maxy = max(y0, y1)
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                rectangle.setAttribute("x", str(minx))
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                rectangle.setAttribute("y", str(miny))
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                rectangle.setAttribute("width", str(maxx - minx))
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                rectangle.setAttribute("height", str(maxy - miny))
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                rectangle.setAttribute("x", str(minx * image.naturalWidth))
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                rectangle.setAttribute("y", str(miny * image.naturalHeight))
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                rectangle.setAttribute("width", str((maxx - minx) * image.naturalWidth))
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                rectangle.setAttribute("height", str((maxy - miny) * image.naturalHeight))
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    rectangle.setAttribute("fill", "none")
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    rectangle.classList.add("shape-bbox")
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        

@@ -71,7 +73,7 @@ def make_bbox(event):

                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    horizontal_ruler.style.display = "none"
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    vertical_ruler_2.style.display = "none"
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    horizontal_ruler_2.style.display = "none"
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                document.body.style.cursor = "auto"
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    zone.removeEventListener("click", create_proxy(make_bbox))
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                return
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        

@@ -88,8 +90,10 @@ def open_shape(event):

                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                global last_click_position, new_shape
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                print("Creating a new shape of type:", shape_type)
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                new_shape = document.createElementNS("http://www.w3.org/2000/svg", "svg")
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            new_shape.setAttribute("width", image.width)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            new_shape.setAttribute("height", image.height)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            new_shape.setAttribute("width", "100%")
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            new_shape.setAttribute("height", "100%")
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            zone_rect = zone.getBoundingClientRect()
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            new_shape.setAttribute("viewBox", f"0 0 {image.naturalWidth} {image.naturalHeight}")
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                if shape_type == "shape-bbox":
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    bbox_pos = None
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        

@@ -99,8 +103,7 @@ def open_shape(event):

                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    )
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    vertical_ruler.style.display = "block"
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    horizontal_ruler.style.display = "block"
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            zone.appendChild(new_shape)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                document.body.style.cursor = "crosshair"
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            for button in list(document.getElementById("shape-selector").children):
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                            
                                

static/style.css

@@ -24,6 +24,8 @@ iconify-icon {

                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                position: absolute;
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                top: 0;
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                left: 0;
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            width: 100%;
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            height: 100%;
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            }
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            .annotation-ruler {
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        

@@ -47,5 +49,8 @@ iconify-icon {

                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            .shape-bbox {
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                stroke: var(--color-accent);
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            fill: var(--color-accent);
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            fill-opacity: 0.1;
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                stroke-width: 2px;
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            vector-effect: non-scaling-stroke;
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            }