Image Segmentation
ultralytics
yolo
yolo11
instance-segmentation
object-detection
floor-plan
architecture
cad
autocad
building-elements
cctv
Eval Results (legacy)
Instructions to use swedishtech/RAQEEB-CCTV with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- ultralytics
How to use swedishtech/RAQEEB-CCTV with ultralytics:
from huggingface_hub import hf_hub_download from ultralytics import YOLO # pick the weights file from this repo's "Files and versions" tab weights = hf_hub_download("swedishtech/RAQEEB-CCTV", "<weights>.pt") model = YOLO(weights) source = 'http://images.cocodataset.org/val2017/000000039769.jpg' model.predict(source=source, save=True) - Notebooks
- Google Colab
- Kaggle
File size: 6,521 Bytes
d0f2b17 | 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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | """CubiCasa SVG core footprints in F1_scaled pixel coordinates.
The upstream loader uses SVG coordinates directly on F1_scaled (the SVG
viewBox can omit the raster's outer margins). Never rescale to viewBox.
Door/window direct child polygons describe the portal, not swing paths.
All results remain research-only and require a recorded visual review.
"""
import json
import re
from collections import Counter
from pathlib import Path
import numpy as np
from defusedxml import ElementTree as ET
from PIL import Image, ImageDraw
from shapely import affinity
from shapely.geometry import Polygon, LineString, box, mapping
from shapely.ops import unary_union, split
from shapely.validation import explain_validity
COLORS = [(225, 55, 55), (40, 180, 70), (30, 120, 240)]
def matrix(value):
result = np.eye(3)
for name, args in re.findall(r'(\w+)\(([^)]*)\)', value or ''):
v = [float(x) for x in re.split(r'[ ,]+', args.strip())]
m = np.eye(3)
if name == 'matrix' and len(v) == 6:
a, b, c, d, e, f = v
m = np.array([[a,c,e],[b,d,f],[0,0,1.]])
elif name == 'translate':
m[:2, 2] = [v[0], v[1] if len(v)>1 else 0]
elif name == 'scale':
m[0,0], m[1,1] = v[0], v[-1]
elif name == 'rotate':
theta = np.deg2rad(v[0]); c, s = np.cos(theta), np.sin(theta)
m[:2,:2] = [[c,-s],[s,c]]
if len(v)==3:
t=np.eye(3); t[:2,2]=v[1:]; u=np.eye(3); u[:2,2]=-np.array(v[1:])
m=t@m@u
else:
raise ValueError(f'Unsupported SVG transform {name}')
result = result @ m
return result
def polygons(g):
if g.is_empty: return []
if g.geom_type == 'Polygon': return [g]
if hasattr(g, 'geoms'):
return [p for part in g.geoms for p in polygons(part)]
return []
def simple_parts(poly, depth=0):
"""Cut wall segments across holes; avoid filling openings in YOLO polygons."""
if not poly.interiors: return [poly]
if depth > 30: raise ValueError('Unresolved holes')
h=Polygon(poly.interiors[0]); x,y=h.representative_point().coords[0]
x0,y0,x1,y1=poly.bounds
# Split along the shorter overall dimension, extending through the wall.
line=LineString([(x0-1,y),(x1+1,y)]) if x1-x0 < y1-y0 else LineString([(x,y0-1),(x,y1+1)])
pieces=polygons(split(poly,line))
if len(pieces)<2: raise ValueError('Hole cut did not split polygon')
return [p for piece in pieces for p in simple_parts(piece,depth+1)]
def parse_core(svg_bytes, width, height, extra_annotations=None):
root=ET.fromstring(svg_bytes)
objects=[]; flags=[]; other=Counter()
def walk(e, parent):
transform=parent@matrix(e.get('transform',''))
kind=e.get('id')
if kind in {'Wall','Door','Window'}:
cid={'Wall':0,'Door':1,'Window':2}[kind]
direct=[c for c in e if c.tag.split('}')[-1]=='polygon']
if not direct: flags.append(f'{kind}:no_direct_polygon')
for el in direct:
nums=[float(v) for v in re.split(r'[\s,]+',el.get('points','').strip()) if v]
if len(nums)<6 or len(nums)%2: flags.append(f'{kind}:malformed'); continue
pts=np.c_[np.array(nums).reshape(-1,2),np.ones(len(nums)//2)]
xy=(transform@matrix(el.get('transform',''))@pts.T).T[:,:2]
p=Polygon(xy)
if not p.is_valid or p.area <=0:
flags.append(f'{kind}:invalid:{explain_validity(p)}'); continue
outside=p.difference(box(0,0,width,height)).area
if outside > max(1.,p.area*.005): flags.append(f'{kind}:out_of_bounds')
p=p.intersection(box(0,0,width,height))
objects.append({'class_id':cid,'geometry':p,'svg_class':e.get('class'), 'source_object':len(objects)})
elif e.get('class'): other[e.get('class').split()[0]]+=1
for c in e: walk(c,transform)
walk(root,np.eye(3))
for extra in extra_annotations or []:
p=Polygon(extra['points'])
if not p.is_valid or p.area<=0:raise ValueError('Invalid reviewed correction')
objects.append({'class_id':extra['class_id'],'geometry':p,'svg_class':'reviewed_correction','source_object':len(objects)})
openings=unary_union([o['geometry'] for o in objects if o['class_id'] in (1,2)])
result=[]
leafless=[]
for obj in objects:
if obj['class_id']==1 and 'None' in (obj.get('svg_class') or '').split():
leafless.append({'source_object':obj['source_object'],'svg_class':obj['svg_class'],'candidate_canonical_id':3,'geometry':mapping(obj['geometry']),'status':'out_of_scope_core; per-image visual confirmation required'})
continue
geom=obj['geometry'].difference(openings) if obj['class_id']==0 else obj['geometry']
for part in polygons(geom):
for p in simple_parts(part):
if p.area<.25: continue
result.append({**obj,'geometry':p})
return result, {'issues':flags,'source_objects':len(objects),'output_instances':dict(Counter(o['class_id'] for o in result)),
'leafless_opening_candidates':leafless,
'other_svg_classes':dict(other),'coordinate_rule':'direct SVG coordinates on F1_scaled; parent transforms applied',
'wall_openings':'subtract all door/window footprints; split wall polygons with interior holes',
'review_status':'pending_visual_review'}
def overlay(image, objects, max_side=1800):
im=image.convert('RGBA'); layer=Image.new('RGBA',im.size)
draw=ImageDraw.Draw(layer)
for obj in objects:
c=COLORS[obj['class_id']]
draw.polygon(list(obj['geometry'].exterior.coords), fill=(*c,90),outline=(*c,255),width=2)
result=Image.alpha_composite(im,layer).convert('RGB')
result.thumbnail((max_side,max_side))
return result
if __name__=='__main__':
import argparse
p=argparse.ArgumentParser(); p.add_argument('folder',type=Path); args=p.parse_args()
im=Image.open(args.folder/'F1_scaled.png')
objects,report=parse_core((args.folder/'model.svg').read_bytes(),*im.size)
overlay(im,objects).save(args.folder/'core_overlay.jpg',quality=95)
(args.folder/'geometry_audit.json').write_text(json.dumps(report,indent=2))
(args.folder/'core_polygons.json').write_text(json.dumps([{**o,'geometry':mapping(o['geometry'])} for o in objects]))
print(json.dumps(report,indent=2))
|