Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOCS-2036: Add vision service example snippets #232

Merged
merged 3 commits into from
Jun 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion lib/src/services/vision.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,24 @@ class VisionClient extends Resource implements ResourceRPCClient {
VisionClient(this.name, this.channel);

/// Get a list of [Detection]s from the camera named [cameraName].
///
/// ```
/// // Example:
/// var detections = await myVisionService.detectionsFromCamera('myWebcam');
/// ```
Future<List<Detection>> detectionsFromCamera(String cameraName, {Map<String, dynamic>? extra}) async {
final request = GetDetectionsFromCameraRequest(name: name, cameraName: cameraName, extra: extra?.toStruct());
final response = await client.getDetectionsFromCamera(request);
return response.detections;
}

/// Get a list of [Detection]s from the provided [image].
/// Get a list of [Detection]s from the provided [ViamImage].
///
/// ```
/// // Example:
/// var latestImage = await myWebcam.image();
/// var detections = await myVisionService.detections(latestImage);
/// ```
Future<List<Detection>> detections(ViamImage image, {Map<String, dynamic>? extra}) async {
final request = GetDetectionsRequest(
name: name,
Expand All @@ -44,6 +55,11 @@ class VisionClient extends Resource implements ResourceRPCClient {

/// Get a list of [Classification]s from the camera named [cameraName].
/// The maximum number of [Classification]s returned is [count].
///
/// ```
/// // Example:
/// var classifications = await myVisionService.classificationsFromCamera('myWebcam', 2);
/// ```
Future<List<Classification>> classificationsFromCamera(String cameraName, int count, {Map<String, dynamic>? extra}) async {
final request = GetClassificationsFromCameraRequest(name: name, cameraName: cameraName, n: count, extra: extra?.toStruct());
final response = await client.getClassificationsFromCamera(request);
Expand All @@ -52,6 +68,12 @@ class VisionClient extends Resource implements ResourceRPCClient {

/// Get a list of [Classification]s from the provided [image].
/// The maximum number of [Classification]s returned is [count].
///
/// ```
/// // Example:
/// var latestImage = await myWebcam.image();
/// var classifications = await myVisionService.classifications(latestImage, 2);
/// ```
Future<List<Classification>> classifications(ViamImage image, int count, {Map<String, dynamic>? extra}) async {
final request = GetClassificationsRequest(
name: name,
Expand All @@ -66,6 +88,11 @@ class VisionClient extends Resource implements ResourceRPCClient {
}

/// Get a list of [PointCloudObject]s from the camera named [cameraName].
///
/// ```
/// // Example:
/// var ptCloud = await myVisionService.objectPointClouds('myCamera');
/// ```
Future<List<PointCloudObject>> objectPointClouds(String cameraName, {Map<String, dynamic>? extra}) async {
final request = GetObjectPointCloudsRequest(name: name, cameraName: cameraName, mimeType: MimeType.pcd.name, extra: extra?.toStruct());
final response = await client.getObjectPointClouds(request);
Expand Down