Пример #1
0
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=font_size,
                  font_family='monospace',
                  font_weight=500)
    doc += defs

    ox1, ox2 = x0 + 20, x0 + width - 20
    oy1, oy2 = y0 + 20 + font_size, y0 + height - 20

    # Classes
    lines = ['%s (%.2f)' % pair for pair in results]
    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')

        doc += svg.Text(line, text_anchor='end', x=ox2, y=y, fill='white')

    # Title
    if title:
        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
    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)
Пример #2
0
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=font_size, font_family='monospace', font_weight=500)
    doc += defs

    for obj in objs:
        percent = int(100 * obj.score)
        if obj.label:
            caption = '%d%% %s' % (percent, obj.label)
        else:
            caption = '%d%%' % percent

        x, y, w, h = obj.bbox.scale(*layout.size)
        color = get_color(obj.id)

        doc += svg.Rect(x=x, y=y, width=w, height=h,
                        style='stroke:%s' % color, _class='bbox')
        doc += svg.Rect(x=x, y=y+h ,
                        width=size_em(len(caption)), height='1.2em', fill=color)
        t = svg.Text(x=x, y=y+h, fill='black')
        t += svg.TSpan(caption, dy='1em')
        doc += t

    ox = x0 + 20
    oy1, oy2 = y0 + 20 + font_size, y0 + height - 20

    # Title
    if title:
        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)
    ]

    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)
Пример #3
0
def overlay(title, objs, get_color, inference_time, inference_rate, layout):
    x0, y0, width, height = layout.window

    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)
    doc += defs

    for obj in objs:
        percent = int(100 * obj.score)
        if obj.label:
            caption = '%d%% %s' % (percent, obj.label)
        else:
            caption = '%d%%' % percent

        x, y, w, h = obj.bbox.scale(*layout.size)
        color = get_color(obj.id)

        doc += svg.Rect(x=x,
                        y=y,
                        width=w,
                        height=h,
                        style='stroke:%s' % color,
                        _class='bbox')
        doc += svg.Rect(x=x,
                        y=y + h,
                        width=size_em(len(caption)),
                        height='1.2em',
                        fill=color)
        #center
        center = ((x + w / 2), (y + h / 2))
        doc += svg.Circle(cx=center[0],
                          cy=center[1],
                          r=5,
                          style='stroke:%s' % color)

        centerPts.append(center)

        for i in range(1, len(centerPts)):
            doc += svg.Line(x1=centerPts[i - 1][0],
                            y1=centerPts[i - 1][1],
                            x2=centerPts[i][0],
                            y2=centerPts[i][1],
                            style='stroke:%s' % color)
            #print(centerPts[i-1][0],centerPts[i-1][1])
        #print(centerPts)

        #corner
        #doc += svg.Circle(cx=x,cy=y,r=10, style='stroke:%s' % color)

        t = svg.Text(x=x, y=y + h, fill='black')
        t += svg.TSpan(caption, dy='1em')
        doc += t

    ox, oy1, oy2 = x0 + 20, y0 + 20, 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

    # 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

    return str(doc)