Skip to content

Commit 00f769b

Browse files
authored
DOCS-3540: Add camera samples (#502)
1 parent 0a6cca9 commit 00f769b

File tree

1 file changed

+51
-2
lines changed

1 file changed

+51
-2
lines changed

src/components/camera/camera.ts

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,29 @@ export interface Camera extends Resource {
3333
/**
3434
* Return a frame from a camera.
3535
*
36+
* @example
37+
*
38+
* ```ts
39+
* const camera = new VIAM.CameraClient(machine, 'my_camera');
40+
* const image = await camera.getImage();
41+
*
42+
* // Convert Uint8Array to base64
43+
* const base64Image = btoa(
44+
* Array.from(image)
45+
* .map((byte) => String.fromCharCode(byte))
46+
* .join('')
47+
* );
48+
*
49+
* // Convert image to base64 and display it
50+
* const imageElement = document.createElement('img');
51+
* imageElement.src = `data:image/jpeg;base64,${base64Image}`;
52+
* const imageContainer = document.getElementById('#imageContainer');
53+
* if (imageContainer) {
54+
* imageContainer.innerHTML = '';
55+
* imageContainer.appendChild(imageElement);
56+
* }
57+
* ```
58+
*
3659
* @param mimeType - A specific MIME type to request. This is not necessarily
3760
* the same type that will be returned.
3861
*/
@@ -41,14 +64,40 @@ export interface Camera extends Resource {
4164
/**
4265
* Render a frame from a camera to an HTTP response.
4366
*
67+
* @example
68+
*
69+
* ```ts
70+
* const camera = new VIAM.CameraClient(machine, 'my_camera');
71+
* const mimeType = 'image/jpeg';
72+
* const image = await camera.renderFrame(mimeType);
73+
* ```
74+
*
4475
* @param mimeType - A specific MIME type to request. This is not necessarily
4576
* the same type that will be returned.
4677
*/
4778
renderFrame: (mimeType?: MimeType, extra?: Struct) => Promise<Blob>;
4879

49-
/** Return a point cloud from a camera. */
80+
/**
81+
* Return a point cloud from a camera.
82+
*
83+
* @example
84+
*
85+
* ```ts
86+
* const camera = new VIAM.CameraClient(machine, 'my_camera');
87+
* const pointCloud = await camera.getPointCloud();
88+
* ```
89+
*/
5090
getPointCloud: (extra?: Struct) => Promise<Uint8Array>;
5191

52-
/** Return the camera properties. */
92+
/**
93+
* Return the camera properties.
94+
*
95+
* @example
96+
*
97+
* ```ts
98+
* const camera = new VIAM.CameraClient(machine, 'my_camera');
99+
* const properties = await camera.getProperties();
100+
* ```
101+
*/
53102
getProperties: () => Promise<Properties>;
54103
}

0 commit comments

Comments
 (0)