# Capture synthetic data with virtual cameras

> Capture color images, depth, point clouds, bounding boxes, and segmentation from cameras in NVIDIA Isaac Sim. Learn how to label objects and call the capture endpoints of the Wandelbots NOVA extension API.

The extension API of Wandelbots NOVA captures data from any camera in the scene.
Use the data to locate workpieces, check a scene, or train and test vision code before the real camera exists.

| Capture | Endpoint | Needs labels | Result |
| - | - | - | - |
| Color image | `GET /periphery/cameras/capture/color` | No | PNG or JPEG. |
| Normals | `GET /periphery/cameras/capture/normals` | No | Normal vector per pixel as JSON, or a colored image. |
| Depth | `GET /periphery/cameras/capture/depth` | No | Distance per pixel and the camera intrinsics as JSON, or a colored image. |
| Point cloud | `GET /periphery/cameras/capture/pointcloud` | Yes | Points, colors, and normals as JSON. |
| 2D bounding boxes | `GET /periphery/cameras/capture/bounding-box-2d` | Yes | Pixel boxes as JSON, or boxes drawn on a color image. |
| 3D bounding boxes | `GET /periphery/cameras/capture/bounding-box-3d` | Yes | Boxes with their transform as JSON, or boxes drawn on a color image. |
| Instance segmentation | `GET /periphery/cameras/capture/instance-segmentation` | Yes | Object ID per pixel and the ID labels as JSON, or a colored mask. |
| Semantic segmentation | `GET /periphery/cameras/capture/semantic-segmentation` | Yes | Class ID per pixel and the class labels as JSON, or a colored mask. |

All paths start with `/omniservice/api/v2`, for example `http://localhost:8011/omniservice/api/v2/periphery/cameras/capture/color`.

### Prerequisites

1. [Install the Wandelbots NOVA extension](/simulation/installation).
2. Add a camera to the scene with `Create` → `Camera`.\
   The API uses existing cameras only. It does not create cameras or change their settings.
3. Open the API reference with `Wandelbots NOVA` → `Omniservice API`.\
   Most calls take a prim path. Copy it from the `Stage` panel with `Copy Prim Path`.

### Step 1: Match the camera to the real camera

Set `Focal Length`, `Horizontal Aperture`, and `Vertical Aperture` of the camera prim to the values of your real camera.
The depth capture calculates the camera intrinsics from these values and the requested resolution.

> **Info:** Some camera manufacturers, for example Zivid, provide an SDK that returns the camera matrix.
> Otherwise, take the values from the data sheet or from a calibration.

To see which cameras the API finds, send [`GET /periphery/cameras/prims`](https://docs.wandelbots.com/simulation/extension-api#list-camera-prims).

### Step 2: Label the objects of interest

Point clouds, bounding boxes, and segmentation only contain objects with a semantic label.

1. Add a label with [`PUT /prims/labels`](https://docs.wandelbots.com/simulation/extension-api#set-semantic-label) and the body `{"prim_path": "/World/workpiece_01", "label": "workpiece"}`.\
   → The label replaces any existing class label of the prim.
2. To see which prims carry a label, send `GET /prims/labels`.\
   → The response lists each labeled prim with its labels.
3. To remove the labels of a prim, send `DELETE /prims/labels` with its `prim_path`.\
   If you leave out `prim_path`, the request removes the labels of every prim in the stage.

The API writes the labels as `class` labels of the Isaac Sim semantics schema.
Read more on [semantic labeling](https://docs.omniverse.nvidia.com/simready/latest/sim-needs/semantic-labeling.html).

### Step 3: Capture data

Call a capture endpoint with these query parameters:

- `camera_prim_path`: The camera to capture from. Without it, the API uses the active viewport camera.
- `width` and `height`: Resolution in pixels. The default is 640 by 480.
- `result_type`: `json` for data, `rgb_png` or `jpeg` for an image.
- `object_class`: Optional. Limit boxes and segmentation to these labels. Repeat the parameter for several labels.

→ The response contains the capture of the current frame. The simulation does not need to run.

## Units and frames

| Capture | Unit and frame |
| - | - |
| Depth | Distance from the camera along each pixel ray, in millimeters by default. Set `unit=m` for meters. Pixels without geometry are `0`. |
| Depth intrinsics | 3 by 3 pinhole matrix in pixels for the requested resolution. It ignores lens distortion. |
| Point cloud | Millimeters in the frame of the camera prim. `downscale_factor` below `1` keeps a random share of the points. |
| 2D bounding boxes | Pixel coordinates `[x_min, y_min, x_max, y_max]`. |
| 3D bounding boxes | `bbox` is the extent in the frame of the object, in millimeters. `transform` is the object-to-world matrix in USD row layout, translation in millimeters. |

> **Warning:** Without labeled objects in view, the captures fail differently.
> The point cloud returns HTTP `422`, segmentation returns HTTP `500`, and bounding boxes return an empty list.

3D bounding boxes include labeled objects outside the camera view.
Filter them by position if you only need visible objects.

## Example

The Python client `wandelbots-isaacsim-api` wraps the endpoints.

```bash
pip install wandelbots-isaacsim-api
```

The following script labels two prims and reads their 2D bounding boxes.

```python
import asyncio

from wandelbots_isaacsim_api import ApiClient, Configuration
from wandelbots_isaacsim_api.api.periphery_camera_api import PeripheryCameraApi
from wandelbots_isaacsim_api.api.prims_api import PrimsApi
from wandelbots_isaacsim_api.models import BodySetSemanticLabel


async def main():
    configuration = Configuration(host="http://localhost:8011/omniservice/api/v2")
    async with ApiClient(configuration) as api_client:
        prims_api = PrimsApi(api_client)
        for prim_path in ("/World/Sphere", "/World/Cube"):
            await prims_api.set_semantic_label(
                BodySetSemanticLabel(prim_path=prim_path, label="workpiece")
            )

        camera_api = PeripheryCameraApi(api_client)
        print(await camera_api.list_camera_prims())

        boxes = await camera_api.capture_boundingbox2d(
            result_type="json", camera_prim_path="/World/Camera", width=400, height=400
        )
        print([(box.prim_path, box.bbox) for box in boxes])


if __name__ == "__main__":
    asyncio.run(main())
```

The script prints the camera prims of the stage, then one entry per labeled prim in view with its box `[x_min, y_min, x_max, y_max]` in pixels.

For more scripts, see [Examples](/simulation/examples).
