> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pixeltable.com/llms.txt
> Use this file to discover all available pages before exploring further.

# vision

> <a href="https://github.com/pixeltable/pixeltable/blob/main/pixeltable/functions/vision.py#L0" id="viewSource" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/badge/View%20Source%20on%20Github-blue?logo=github&labelColor=gray" alt="View Source on GitHub" style={{ display: 'inline', margin: '0px' }} noZoom /></a>

# <span style={{ 'color': 'gray' }}>module</span>  pixeltable.functions.vision

Pixeltable UDFs for Computer Vision.

Example:

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
import pixeltable as pxt
from pixeltable.functions import vision as pxtv

t = pxt.get_table(...)
t.select(pxtv.draw_bounding_boxes(t.img, boxes=t.boxes, label=t.labels)).collect()
```

## <span style={{ 'color': 'gray' }}>udf</span>  draw\_bounding\_boxes()

```python Signature theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
@pxt.udf
draw_bounding_boxes(
    img: pxt.Image,
    boxes: pxt.Json,
    labels: pxt.Json | None = None,
    color: pxt.String | None = None,
    box_colors: pxt.Json | None = None,
    fill: pxt.Bool = False,
    width: pxt.Int = 1,
    font: pxt.String | None = None,
    font_size: pxt.Int | None = None
) -> pxt.Image
```

Draws bounding boxes on the given image.

Labels can be any type that supports `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`](https://pillow.readthedocs.io/en/stable/reference/ImageColor.html#imagecolor-module) module or as
RGB hex codes (e.g., '#FF0000').

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.
* **`fill`** (`pxt.Bool`): Whether to fill the bounding boxes with color.
* **`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 by
  [`PIL.ImageFont.truetype()`](https://pillow.readthedocs.io/en/stable/reference/ImageFont.html#PIL.ImageFont.truetype).
  If `None`, uses the default provided by
  [`PIL.ImageFont.load_default()`](https://pillow.readthedocs.io/en/stable/reference/ImageFont.html#PIL.ImageFont.load_default).
* **`font_size`** (`pxt.Int | None`): Size of the font used for labels in points. Only used in conjunction with non-`None` `font` argument.

**Returns:**

* `pxt.Image`: The image with bounding boxes drawn on it.

## <span style={{ 'color': 'gray' }}>udf</span>  eval\_detections()

```python Signature theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
@pxt.udf
eval_detections(
    pred_bboxes: pxt.Json,
    pred_labels: pxt.Json,
    pred_scores: pxt.Json,
    gt_bboxes: pxt.Json,
    gt_labels: pxt.Json,
    min_iou: pxt.Float = 0.5
) -> pxt.Json
```

Evaluates the performance of a set of predicted bounding boxes against a set of ground truth bounding boxes.

**Parameters:**

* **`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.

**Returns:**

* `pxt.Json`: A list of dictionaries, one per label class, with the following structure:
  ```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
  {
      'min_iou': float,  # The value of `min_iou` used for the detections
      'class': int,  # The label class
      'tp': list[int],  # List of 1's and 0's indicating true positives for each
                        # predicted bounding box of this class
      'fp': list[int],  # List of 1's and 0's indicating false positives for each
                        # predicted bounding box of this class; `fp[n] == 1 - tp[n]`
      'scores': list[float],  # List of predicted scores for each bounding box of this class
      'num_gts': int,  # Number of ground truth bounding boxes of this class
  }
  ```
