Interface Camera

Represents any physical hardware that can capture frames.

interface Camera {
    getGeometries: (extra?: Struct) => Promise<commonApi.Geometry[]>;
    getImage: (mimeType?: MimeType, extra?: Struct) => Promise<Uint8Array>;
    getImages: (
        filterSourceNames?: string[],
        extra?: Struct,
    ) => Promise<{ images: NamedImage[]; metadata: ResponseMetadata }>;
    getPointCloud: (extra?: Struct) => Promise<Uint8Array>;
    getProperties: () => Promise<Properties>;
    name: string;
    renderFrame: (mimeType?: MimeType, extra?: Struct) => Promise<Blob>;
    doCommand(command: Struct): Promise<JsonValue>;
}

Hierarchy (View Summary)

Implemented by

Properties

getGeometries: (extra?: Struct) => Promise<commonApi.Geometry[]>

Get the geometries of the component in their current configuration

getImage: (mimeType?: MimeType, extra?: Struct) => Promise<Uint8Array>

Return a frame from a camera.

Type declaration

    • (mimeType?: MimeType, extra?: Struct): Promise<Uint8Array>
    • Parameters

      • OptionalmimeType: MimeType

        A specific MIME type to request. This is not necessarily the same type that will be returned.

      • Optionalextra: Struct

      Returns Promise<Uint8Array>

const camera = new VIAM.CameraClient(machine, 'my_camera');
const image = await camera.getImage();

// Convert Uint8Array to base64
const base64Image = btoa(
Array.from(image)
.map((byte) => String.fromCharCode(byte))
.join('')
);

// Convert image to base64 and display it
const imageElement = document.createElement('img');
imageElement.src = `data:image/jpeg;base64,${base64Image}`;
const imageContainer = document.getElementById('#imageContainer');
if (imageContainer) {
imageContainer.innerHTML = '';
imageContainer.appendChild(imageElement);
}

For more information, see Camera API.

getImages: (
    filterSourceNames?: string[],
    extra?: Struct,
) => Promise<{ images: NamedImage[]; metadata: ResponseMetadata }>

Return a frame from a camera.

Type declaration

    • (
          filterSourceNames?: string[],
          extra?: Struct,
      ): Promise<{ images: NamedImage[]; metadata: ResponseMetadata }>
    • Parameters

      • OptionalfilterSourceNames: string[]

        A list of source names to filter the images by. If empty or undefined, all images will be returned.

      • Optionalextra: Struct

        Extra parameters to pass to the camera.

      Returns Promise<{ images: NamedImage[]; metadata: ResponseMetadata }>

const camera = new VIAM.CameraClient(machine, 'my_camera');
const images = await camera.getImages();

TODO(docs): include docs link for get images TS example

getPointCloud: (extra?: Struct) => Promise<Uint8Array>

Return a point cloud from a camera.

const camera = new VIAM.CameraClient(machine, 'my_camera');
const pointCloud = await camera.getPointCloud();

For more information, see Camera API.

getProperties: () => Promise<Properties>

Return the camera properties.

const camera = new VIAM.CameraClient(machine, 'my_camera');
const properties = await camera.getProperties();

For more information, see Camera API.

name: string

The name of the resource.

renderFrame: (mimeType?: MimeType, extra?: Struct) => Promise<Blob>

Render a frame from a camera to an HTTP response.

Type declaration

    • (mimeType?: MimeType, extra?: Struct): Promise<Blob>
    • Parameters

      • OptionalmimeType: MimeType

        A specific MIME type to request. This is not necessarily the same type that will be returned.

      • Optionalextra: Struct

      Returns Promise<Blob>

const camera = new VIAM.CameraClient(machine, 'my_camera');
const mimeType = 'image/jpeg';
const image = await camera.renderFrame(mimeType);

For more information, see Camera API.

Methods

  • Send/Receive arbitrary commands to the resource.

    Parameters

    • command: Struct

      The command to execute.

    Returns Promise<JsonValue>

    import { Struct } from '@viamrobotics/sdk';

    const result = await resource.doCommand(
    Struct.fromJson({
    myCommand: { key: 'value' },
    })
    );