BramboxViewer

class ibb.widgets.BramboxViewer(**kwargs: Any)[source]

This widget can visualize a brambox dataset as bounding boxes drawn on top of the images.
Its arguments work a lot like brambox.util.BoxDrawer.

Parameters
  • images (callable or dict-like object) – A way to get the image or path to the image from the image labels in the dataframe

  • boxes (pandas.DataFrame) – Bounding boxes to draw

  • label (pandas.Series) – Label to write above the boxes; Default class_label (confidence)

  • color (pandas.Series) – Color to use for drawing; Default every class_label will get its own color, up to 10 labels

  • size (pandas.Series) – Thickness of the border of the bounding boxes; Default 3

  • alpha (pandas.Series) – Alpha fill value of the bounding boxes; Default 00

  • **kwargs (dict) – Extra keyword arguments that will be passed to Viewer

Note

If the images argument is callable, the image or path to the image will be retrieved in the following way: >>> image = images(image_label)

Otherwise the image or path is retrieved as: >>> image = images[image_label]

Note

The label, color, size and alpha arguments can also be tacked on to the boxes dataframe as columns. They can also be a single value, which will then be used for each bounding box.
Basically, as long as you can assign the value as a new column to the dataframe, it will work.

Examples

Warning

Note that the widgets are not responding as we do not have a python backend running!

[1]:
import brambox as bb
import ibb
[2]:
# Load annotations
anno = bb.io.load('pandas', 'annotations.h5')
anno
[2]:
image class_label id x_top_left y_top_left width height occluded truncated lost difficult ignore
0 000001 dog NaN 48.0 240.0 147.0 131.0 0.0 1.0 False False False
1 000001 person NaN 8.0 12.0 344.0 486.0 0.0 1.0 False False False
2 000002 train NaN 139.0 200.0 68.0 101.0 0.0 0.0 False False False
3 000003 sofa NaN 123.0 155.0 92.0 40.0 0.0 0.0 False False False
4 000003 chair NaN 239.0 156.0 68.0 49.0 0.0 0.0 False False False
5 000004 car NaN 13.0 311.0 71.0 51.0 0.0 0.0 False False False
6 000004 car NaN 362.0 330.0 138.0 59.0 0.0 1.0 False False False
7 000004 car NaN 235.0 328.0 99.0 47.0 0.0 0.0 False False False
8 000004 car NaN 175.0 327.0 77.0 37.0 0.0 0.0 False False False
9 000004 car NaN 139.0 320.0 50.0 39.0 0.0 0.0 False False False
10 000004 car NaN 108.0 325.0 42.0 28.0 0.0 0.0 False False False
11 000004 car NaN 84.0 323.0 37.0 27.0 0.0 0.0 False False False
[3]:
v = ibb.BramboxViewer(
    # Dictionary or Function to map image column to image paths
    lambda name: f'images/{name}.jpg',
    anno,
)
v
[3]:
[4]:
# Load Detections
det = bb.io.load('pandas', 'detections.h5')
det
[4]:
image class_label id x_top_left y_top_left width height confidence
0 000001 person NaN 270.069856 55.980325 35.082728 99.642827 0.002556
1 000001 tvmonitor NaN 5.429369 80.088432 26.879914 99.102836 0.001120
2 000001 person NaN 273.802024 96.162503 32.399382 73.652089 0.034645
3 000001 person NaN 318.425435 77.141560 28.912620 123.342065 0.008122
4 000001 person NaN 352.354380 93.409190 9.711184 83.560586 0.001517
... ... ... ... ... ... ... ... ...
164 000004 car NaN 67.649786 306.099818 296.283392 96.845572 0.001021
165 000004 motorbike NaN -35.525570 334.530390 342.759683 109.085184 0.001464
166 000004 car NaN 6.774407 340.022931 330.145946 97.088520 0.001446
167 000004 person NaN 41.884642 136.205545 339.365922 438.765929 0.001059
168 000004 bus NaN 123.889300 143.956826 334.710195 428.265535 0.001212

169 rows × 8 columns

[5]:
ibb.BramboxViewer(
    # Dictionary or Function to map image column to image paths
    lambda name: f'images/{name}.jpg',
    det,

    # Scale border size, based on confidence levels
    size=det.confidence * 5,
)
[5]: