-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RSDK-7392] vision service client (#196)
- Loading branch information
Showing
8 changed files
with
539 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import 'package:fixnum/fixnum.dart'; | ||
import 'package:grpc/grpc_connection_interface.dart'; | ||
|
||
import '../../protos/common/common.dart'; | ||
import '../../protos/service/vision.dart'; | ||
import '../media/image.dart'; | ||
import '../resource/base.dart'; | ||
import '../utils.dart'; | ||
|
||
class VisionClient implements ResourceRPCClient { | ||
final String name; | ||
|
||
@override | ||
ClientChannelBase channel; | ||
|
||
@override | ||
VisionServiceClient get client => VisionServiceClient(channel); | ||
|
||
VisionClient(this.name, this.channel); | ||
|
||
/// Get a list of [Detection]s from the camera named [cameraName]. | ||
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]. | ||
Future<List<Detection>> detections(ViamImage image, {Map<String, dynamic>? extra}) async { | ||
final request = GetDetectionsRequest( | ||
name: name, | ||
image: image.raw, | ||
width: Int64(image.image?.width ?? 0), | ||
height: Int64(image.image?.height ?? 0), | ||
mimeType: image.mimeType.name, | ||
extra: extra?.toStruct()); | ||
final response = await client.getDetections(request); | ||
return response.detections; | ||
} | ||
|
||
/// Get a list of [Classification]s from the camera named [cameraName]. | ||
/// The maximum number of [Classification]s returned is [count]. | ||
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); | ||
return response.classifications; | ||
} | ||
|
||
/// Get a list of [Classification]s from the provided [image]. | ||
/// The maximum number of [Classification]s returned is [count]. | ||
Future<List<Classification>> classifications(ViamImage image, int count, {Map<String, dynamic>? extra}) async { | ||
final request = GetClassificationsRequest( | ||
name: name, | ||
image: image.raw, | ||
width: image.image?.width, | ||
height: image.image?.height, | ||
mimeType: image.mimeType.name, | ||
n: count, | ||
extra: extra?.toStruct()); | ||
final response = await client.getClassifications(request); | ||
return response.classifications; | ||
} | ||
|
||
/// Get a list of [PointCloudObject]s from the camera named [cameraName]. | ||
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); | ||
return response.objects; | ||
} | ||
|
||
/// Send/Receive arbitrary commands to the Resource | ||
Future<Map<String, dynamic>> doCommand(Map<String, dynamic> command) async { | ||
final request = DoCommandRequest() | ||
..name = name | ||
..command = command.toStruct(); | ||
final response = await client.doCommand(request); | ||
return response.result.toMap(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.