Add visual separation between text lines.
Change-Id: I5235592a4e29b5827adb9ca6f6e6ff1eb5f7c61a
diff --git a/edgetpuvision/classify.py b/edgetpuvision/classify.py
index 51119ad..6cbcf8b 100644
--- a/edgetpuvision/classify.py
+++ b/edgetpuvision/classify.py
@@ -20,54 +20,53 @@
CSS_STYLES = str(svg.CssStyle({'.back': svg.Style(fill='black',
stroke='black',
- stroke_width='1em')}))
+ stroke_width='0.5em')}))
def size_em(length):
return '%sem' % str(0.6 * length)
def overlay(title, results, inference_time, inference_rate, layout):
x0, y0, width, height = layout.window
+ font_size = 0.03 * height
defs = svg.Defs()
defs += CSS_STYLES
doc = svg.Svg(width=width, height=height,
viewBox='%s %s %s %s' % layout.window,
- font_size='1em', font_family='monospace', font_weight=500)
+ font_size=font_size, font_family='monospace', font_weight=500)
doc += defs
ox1, ox2 = x0 + 20, x0 + width - 20
- oy1, oy2 = y0 + 20, y0 + height - 20
+ oy1, oy2 = y0 + 20 + font_size, y0 + height - 20
# Classes
lines = ['%s (%.2f)' % pair for pair in results]
- if lines:
- text_width = size_em(max(len(line) for line in lines))
- text_height = '%sem' % len(lines)
- doc += svg.Rect(x=0, y=0, width=text_width, height=text_height,
- transform='translate(%s, %s) scale(-1,-1)' % (ox2, oy2),
+ for i, line in enumerate(lines):
+ y = oy2 - i * 1.7 * font_size
+
+ doc += svg.Rect(x=0, y=0, width=size_em(len(line)), height='1em',
+ transform='translate(%s, %s) scale(-1,-1)' % (ox2, y),
_class='back')
- t = svg.Text(y=oy2, fill='white', text_anchor='end')
- for i, line in enumerate(lines):
- dy = '-1em' if i > 0 else '0em'
- t += svg.TSpan(line, x=ox2, dy=dy)
- doc += t
+
+ doc += svg.Text(line, text_anchor='end', x=ox2, y=y, fill='white')
# Title
if title:
- doc += svg.Rect(x=ox1, y=oy1,
- width=size_em(len(title)), height='1em',
- _class='back')
- t = svg.Text(x=ox1, y=oy1, fill='white')
- t += svg.TSpan(title, dy='1em')
- doc +=t
+ doc += svg.Rect(x=0, y=0, width=size_em(len(title)), height='1em',
+ transform='translate(%s, %s) scale(1,-1)' % (ox1, oy1), _class='back')
+ doc += svg.Text(title, x=ox1, y=oy1, fill='white')
# Info
- line = 'Inference time: %.2f ms (%.2f fps)' % (inference_time * 1000, 1.0 / inference_time)
- doc += svg.Rect(x=0, y=0, width=size_em(len(line)), height='1em',
- transform='translate(%s, %s) scale(1,-1)' % (ox1, oy2),
- _class='back')
- doc += svg.Text(line, x=ox1, y=oy2, fill='white')
+ lines = [
+ 'Inference time: %.2f ms (%.2f fps)' % (inference_time * 1000, 1.0 / inference_time)
+ ]
+
+ for i, line in enumerate(reversed(lines)):
+ y = oy2 - i * 1.7 * font_size
+ doc += svg.Rect(x=0, y=0, width=size_em(len(line)), height='1em',
+ transform='translate(%s, %s) scale(1,-1)' % (ox1, y), _class='back')
+ doc += svg.Text(line, x=ox1, y=y, fill='white')
return str(doc)
diff --git a/edgetpuvision/detect.py b/edgetpuvision/detect.py
index b50f795..dbaf005 100644
--- a/edgetpuvision/detect.py
+++ b/edgetpuvision/detect.py
@@ -25,9 +25,9 @@
CSS_STYLES = str(svg.CssStyle({'.back': svg.Style(fill='black',
stroke='black',
- stroke_width='1em'),
+ stroke_width='0.5em'),
'.bbox': svg.Style(fill_opacity=0.0,
- stroke_width='2px')}))
+ stroke_width='0.1em')}))
BBox = collections.namedtuple('BBox', ('x', 'y', 'w', 'h'))
BBox.area = lambda self: self.w * self.h
@@ -59,13 +59,14 @@
def overlay(title, objs, get_color, inference_time, inference_rate, layout):
x0, y0, width, height = layout.window
+ font_size = 0.03 * height
defs = svg.Defs()
defs += CSS_STYLES
doc = svg.Svg(width=width, height=height,
viewBox='%s %s %s %s' % layout.window,
- font_size='1em', font_family='monospace', font_weight=500)
+ font_size=font_size, font_family='monospace', font_weight=500)
doc += defs
for obj in objs:
@@ -86,30 +87,26 @@
t += svg.TSpan(caption, dy='1em')
doc += t
-
- ox, oy1, oy2 = x0 + 20, y0 + 20, y0 + height - 20
+ ox = x0 + 20
+ oy1, oy2 = y0 + 20 + font_size, y0 + height - 20
# Title
if title:
- doc += svg.Rect(x=ox, y=oy1,
- width=size_em(len(title)), height='1em',
- _class='back')
- t = svg.Text(x=ox, y=oy1, fill='white')
- t += svg.TSpan(title, dy='1em')
- doc +=t
+ doc += svg.Rect(x=0, y=0, width=size_em(len(title)), height='1em',
+ transform='translate(%s, %s) scale(1,-1)' % (ox, oy1), _class='back')
+ doc += svg.Text(title, x=ox, y=oy1, fill='white')
# Info
lines = [
'Objects: %d' % len(objs),
'Inference time: %.2f ms (%.2f fps)' % (inference_time * 1000, 1.0 / inference_time)
]
- text_width = size_em(max(len(line) for line in lines))
- doc += svg.Rect(x=0, y=0, width=text_width, height='2.2em',
- transform='translate(%s, %s) scale(1,-1)' % (ox, oy2), _class='back')
- t = svg.Text(y=oy2, fill='white')
- t += svg.TSpan(lines[0], x=ox)
- t += svg.TSpan(lines[1], x=ox, dy='-1.2em')
- doc += t
+
+ for i, line in enumerate(reversed(lines)):
+ y = oy2 - i * 1.7 * font_size
+ doc += svg.Rect(x=0, y=0, width=size_em(len(line)), height='1em',
+ transform='translate(%s, %s) scale(1,-1)' % (ox, y), _class='back')
+ doc += svg.Text(line, x=ox, y=y, fill='white')
return str(doc)