diff --git a/requirements.txt b/requirements.txt index a41560c..f5184af 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,4 @@ coloredlogs pycocotools numpy mahotas +svgwrite \ No newline at end of file diff --git a/tools.py b/tools.py index 9e37f6a..df6dd00 100644 --- a/tools.py +++ b/tools.py @@ -57,6 +57,16 @@ argParser.add_argument( metavar="SVG_FILENAME", help=""" Create an SVG with sticker pages (afterwards convert to EPS: \"for f in *; do echo $f; inkscape -f $f --export-eps $f.eps; done\") + To PDF: + for f in stickers-v1/*.svg; do echo $f; inkscape $f -o pdf/$f.pdf; done + pdfunite stickers-v1/*.pdf stickers-v1.pdf + """ + ) +argParser.add_argument( + '--no-texture', + action='store_true', + help=""" + Don't fill with texture, but only print cut lines """ ) args = argParser.parse_args() @@ -200,7 +210,8 @@ if args.stickers: size = (105, 148) # in mm sizeFactor = 5 # influences the size of the patterns viewBoxSize = (size[0] * sizeFactor, size[1] * sizeFactor) - margin = 5 + margin = 10 + textMargin = 5 gridSize = ( int((viewBoxSize[0]-((grid[0]+1)*margin))/grid[0]), int((viewBoxSize[1]-((grid[1]+1)*margin))/grid[1]) @@ -211,6 +222,7 @@ if args.stickers: nr = 0 total_nr = len(coco.cats) + max_cat_id = max([cid for cid, _ in coco.cats.items()]) for category_id, cat in coco.cats.items(): nr+=1 filename = os.path.join( @@ -228,6 +240,7 @@ if args.stickers: ) inkscape = Inkscape(dwg) + # Layers/groups to cut stickers at 123stickers.nl contourG = inkscape.layer(label='Snijlijnen') drawingG = inkscape.layer(label='Shapes') @@ -237,27 +250,29 @@ if args.stickers: font_size = 10 + # COCO cat id's go until 90, whereas there's only 80 categories. + # for consistency, we stick with id instead of the nr. text = dwg.text( - f"{nr:02d}/{total_nr}", - insert=(margin, margin+font_size), font_size=font_size, fill='black' + f"{category_id:02d}/{max_cat_id}", + insert=(textMargin, textMargin+font_size), font_size=font_size, fill='black', font_family='Arial', ) drawingG.add(text) text = dwg.text( - f"{category_id}. {cat['supercategory']} - {cat['name']}", - insert=(viewBoxSize[0]-margin, margin+font_size), font_size=font_size, fill='black', + f"{cat['supercategory']} - {cat['name']}", + insert=(viewBoxSize[0]-textMargin, textMargin+font_size), font_size=font_size, fill='black', font_family='Arial', style='text-anchor:end;') drawingG.add(text) text = dwg.text( f"Common Objects In Context", - insert=(margin, viewBoxSize[1]-margin), font_size=font_size, fill='black', + insert=(textMargin, viewBoxSize[1]-textMargin), font_size=font_size, fill='black', font_family='Arial', ) drawingG.add(text) text = dwg.text( - f"Plotting Data", - insert=(viewBoxSize[0]-margin, viewBoxSize[1]-margin), font_size=font_size, fill='black', + f"http://plottingd.at/a", + insert=(viewBoxSize[0]-textMargin, viewBoxSize[1]-textMargin), font_size=font_size, fill='black', font_family='Arial', style='text-anchor:end;') drawingG.add(text) @@ -283,14 +298,17 @@ if args.stickers: drawingG.add(position2G) - xml = dwg.get_xml() - with open('textures.xml', 'r') as fp: - textureTree = ElementTree.fromstring(fp.read()) - defsTree = xml.find('defs') - for pattern in textureTree: - defsTree.append(pattern) + + if not args.no_texture: + with open('textures.xml', 'r') as fp: + textureTree = ElementTree.fromstring(fp.read()) + defsTree = xml.find('defs') + for pattern in textureTree: + defsTree.append(pattern) + xmlString = ElementTree.tostring(xml) + with open(filename, 'wb') as fp: # print(xmlString) fp.write(xmlString) diff --git a/www/index.html b/www/index.html index 8428ffd..80e671c 100644 --- a/www/index.html +++ b/www/index.html @@ -1,5 +1,6 @@
+