import base64 from box_utils import cxywh2ltrb, cxywh2xywh def style(): """ Style string for card models """ return """ """ def convert_img_url(img_url): return img_url.replace('http://images.cocodataset.org', 'https://s3.us-east-1.amazonaws.com/images.cocodataset.org') def card(img_url, img_w, img_h, boxes): """ This is a hack to streamlit Solution thanks to: https://discuss.streamlit.io/t/display-svg/172/5 Converting SVG to Base64 and display with tag. Also we used the """ _boxes = "" img_url = convert_img_url(img_url) for b in boxes: _id, cx, cy, w, h, label, logit, is_selected = b[:8] x, y, w, h = cxywh2xywh(cx, cy, w, h) x = round(img_w * x) y = round(img_h * y) w = round(img_w * w) h = round(img_h * h) logit = "%.3f" % logit _boxes += f''' {label}: {logit} ''' _svg = f''' {_boxes} ''' _svg = r'' % \ base64.b64encode(_svg.encode('utf-8')).decode('utf-8') _img_d = f'''
{_svg}
''' return _img_d def obj_card(img_url, img_w, img_h, cx, cy, w, h, *args, dst_len=100): """object card for displaying cropped object Args: Retrieved image and object info Returns: _obj_html: html string to display object """ img_url = convert_img_url(img_url) w = img_w * w h = img_h * h s = max(w, h) x = round(img_w * cx - s / 2) y = round(img_h * cy - s / 2) scale = dst_len / s _obj_html = f'''
''' return _obj_html