module pixeltable.functions.vision
Pixeltable UDFs for Computer Vision. Example:udf bboxes_convert()
Signature
bboxes(pxt.Json): List of bounding boxes, each either specified with absolute pixel coordinates or relative coordinates in [0, 1].src_format(pxt.String): Source format, one of ‘xyxy’, ‘xywh’, ‘cxcywh’.dst_format(pxt.String): Destination format, one of ‘xyxy’, ‘xywh’, ‘cxcywh’.
pxt.Json: List of bounding boxes in dst_format.
udf bboxes_draw()
Signature
str() and is hashable (e.g., strings, ints, etc.).
Colors can be specified as common HTML color names (e.g., ‘red’) supported by PIL’s
ImageColor module or as
RGB/RGBA hex codes (e.g., ‘#FF0000’, ‘#FF0000FF’). If opacity isn’t specified in the color string and
alpha/fill_alpha is None, defaults to 1.0 for box borders and 0.5 for filled boxes.
If no colors are specified, this function randomly assigns each label a specific color based on a hash of the label.
Parameters:
img(pxt.Image): The image on which to draw the bounding boxes.boxes(pxt.Json): List of bounding boxes, each represented as [xmin, ymin, xmax, ymax].labels(pxt.Json | None): List of labels for each bounding box.color(pxt.String | None): Single color to be used for all bounding boxes and labels.box_colors(pxt.Json | None): List of colors, one per bounding box.alpha(pxt.Float | None): Opacity (0-1) of the bounding box borders and labels. If non-None, overrides any alpha incolor/box_colors.fill(pxt.Bool): Whether to fill the bounding boxes with color.fill_alpha(pxt.Float | None): Opacity (0-1) of the bounding box fill. If non-None, overrides any alpha incolor/box_colors.width(pxt.Int): Width of the bounding box borders.font(pxt.String | None): Name of a system font or path to a TrueType font file, as required byPIL.ImageFont.truetype(). IfNone, uses the default provided byPIL.ImageFont.load_default().font_size(pxt.Int | None): Size of the font used for labels in points. Only used in conjunction with non-Nonefontargument.
pxt.Image: The image with bounding boxes drawn on it.
udf bboxes_resize()
Signatures
- to a specified width or height (the other dimension is scaled to maintain the aspect ratio)
- to a specified aspect ratio
width, height, or aspect can be specified.
Parameters:
bboxes(Json): List of bounding boxes, each either specified with absolute pixel coordinates or relative coordinates in [0, 1].format(String): Format of the bounding box coordinates, one of ‘xyxy’, ‘xywh’, ‘cxcywh’.width(Int | None, default:Literal(None)): Target width. Pass anintfor absolute pixels or afloatfor relative coordinates.height(Int | None, default:Literal(None)): Target height. Pass anintfor absolute pixels or afloatfor relative coordinates.aspect(String | None, default:Literal(None)): Target aspect ratio. Pass astrlike ‘16:9’ or afloatlike 1.78.aspect(String | None, default:Literal(None)): Target aspect ratio as a string ‘W:H’ (e.g., ‘16:9’) or afloat. Resizes either the width or height to match the specified aspect ratio, maintaining the other dimension. Requiresaspect_mode.aspect_mode(String | None, default:Literal(None)): Either ‘crop’ or ‘pad’. Required whenaspectis specified. Ifcrop, reduces the oversized dimension to match the aspect ratio. Ifpad, extends the undersized dimension to match the aspect ratio.
pxt.Json: List of resized bounding boxes in the same format as the input.
udf eval_detections()
Signature
pred_bboxes(pxt.Json): List of predicted bounding boxes, each represented as [xmin, ymin, xmax, ymax].pred_labels(pxt.Json): List of predicted labels.pred_scores(pxt.Json): List of predicted scores.gt_bboxes(pxt.Json): List of ground truth bounding boxes, each represented as [xmin, ymin, xmax, ymax].gt_labels(pxt.Json): List of ground truth labels.min_iou(pxt.Float): Minimum intersection-over-union (IoU) threshold for a predicted bounding box to be considered a true positive.
pxt.Json: A list of dictionaries, one per label class, with the following structure: