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

# Box

> Draw bounding boxes on detected objects.

## Overview

Simple and efficient bounding box visualization for object detection results. Automatically adapts line thickness based on image dimensions for optimal visibility.

## Function Signature

```python theme={null}
box(
    image: np.ndarray,
    detections: Detections,
    thickness: Optional[int] = None,
    colors: Optional[List[tuple]] = None
) -> np.ndarray
```

## Parameters

<ParamField path="image" type="np.ndarray" required>
  Input image to draw boxes on (BGR format). Modified in-place with drawn bounding boxes.
</ParamField>

<ParamField path="detections" type="Detections" required>
  Detections object containing bounding boxes. Each detection must have a 'bbox' attribute with (x1, y1, x2, y2) coordinates.
</ParamField>

<ParamField path="thickness" type="Optional[int]" optional default="None">
  Line thickness for bounding boxes in pixels. If None, automatically determined based on image size.
</ParamField>

<ParamField path="colors" type="Optional[List[tuple]]" optional default="None">
  List of BGR color tuples to override default colors. Colors are mapped to unique class\_ids in order of appearance. If None, uses default ColorManager colors.
</ParamField>

## Returns

<ResponseField name="result" type="np.ndarray">
  Image with bounding boxes drawn. The input image is modified in-place.
</ResponseField>

## Examples

<CodeGroup>
  ```python Example theme={null}
  import cv2
  import pixelflow as pf
  from ultralytics import YOLO

  # Load image and get model predictions
  image = cv2.imread("path/to/image.jpg")
  model = YOLO("yolo11n.pt")
  outputs = model.predict(image)  # Raw model outputs
  detections = pf.results.from_ultralytics(outputs)  # Convert to PixelFlow format

  # Draw boxes with default colors and adaptive thickness
  annotated = pf.annotators.box(image, detections)

  # Override with custom colors for specific classes
  custom_colors = [(255, 0, 0), (0, 255, 0), (0, 0, 255)]  # Blue, Green, Red
  annotated = pf.annotators.box(image, detections, colors=custom_colors)

  # Use custom thickness for fine control
  annotated = pf.annotators.box(image, detections, thickness=3)

  # Combine with other annotators for comprehensive visualization
  annotated = pf.annotators.box(image, detections, thickness=2)

  ```
</CodeGroup>

## Error Handling

<Warning>
  This function may raise the following exceptions:

  * **AttributeError**: If detection objects lack required 'bbox' attribute.
  * **ValueError**: If bounding box coordinates are invalid or out of bounds.
</Warning>

## Notes

<Note>
  * Input image is modified in-place for memory efficiency
  * Thickness automatically adapts to image dimensions when not specified
  * Coordinates are automatically converted to integers for drawing
  * Color selection uses ColorManager for consistent visualization across detections
</Note>
