# LeapImageWithBBox

Used to visualize an image overlayed with bounding boxes

```python
import numpy.typing as npt
from code_loader.contract.enums import LeapDataType

@dataclass
class BoundingBox:
    x: float
    y: float
    width: float
    height: float
    confidence: float
    label: str
    rotation: float = 0.0
    metadata: Optional[Dict[str, Union[str, int, float]]] = None

@dataclass
class LeapImageWithBBox:
    data: Union[npt.NDArray[np.float32], npt.NDArray[np.uint8]]
    bounding_boxes: List[BoundingBox]
    type: LeapDataType = LeapDataType.ImageWithBBox
```

<table><thead><tr><th width="167.39065467110788">Args</th><th></th></tr></thead><tbody><tr><td><code>data</code></td><td>an np.ndarray uint8/float32 representation of the image. The expected image format is [H,W,1] OR [H,W,3] and is expected to be in [0,255].</td></tr><tr><td><code>bounding_boxes</code></td><td><p>A list of bounding box. Each bounding_box has the following attributes:<br></p><ul><li>x - x center of the bounding box. Expected to be between [0,1]</li><li>y - y center of the bounding box. Expected to be between [0,1]</li><li>width - width of the bounding box. Expected to be between [0,1]</li><li>height - height of the bounding box. Expected to be between [0,1]</li><li>confidence - the confidence of the prediction. Expected to be between [0,1]. Ground Truth should be set to 1.</li><li>label - a str label of the prediction</li><li>rotation - a float between [0,360] that represents the degree of roation. Defaults to 0.</li><li>metadata (optional) - a metadata on the bounding box. A dictionary of property names (str) to their values (str/int/float)</li></ul></td></tr></tbody></table>

## Examples

#### Basic Usage

```python
from code_loader.contract.visualizer_classes import LeapImageWithBBox
import numpy as np
from code_loader.contract.enums import LeapDataType
...
@tensorleap_custom_visualizer("bb_gt_decoder", LeapDataType.ImageWithBBox)
def gt_bb_decoder(image: np.ndarray, bb_gt: np.ndarray) -> LeapImageWithBBox:
    bbox = [BoundingBox(x=bbx[0], y=bbx[1], width=bbx[2], height=bbx[3], confidence=1, label=all_clss.get(int(bbx[4]) if not np.isnan(bbx[4]) else -1, 'Unknown Class')) for bbx in bb_gt.squeeze(0)]
    image = image.squeeze(0)
    return LeapImageWithBBox(data=image, bounding_boxes=bbox)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.tensorleap.ai/tensorleap-integration/python-api/code_loader/visualizer_classes/leapimagewithbbox.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
