run method
Runs this command.
The return value is wrapped in a Future
if necessary and returned by
CommandRunner.runCommand
.
Implementation
@override
void run() async {
try {
await initializeGoogleVision();
final annotatedResponses = await annotateImage();
final scores = <double>[];
(argResults!['features'] as String).split(',').forEach((feature) {
switch (AnnotationType.values.byName(feature)) {
case AnnotationType.faceDetection:
scores.addAll(annotatedResponses.responses.first.faceAnnotations
.map((faceAnnotation) => faceAnnotation.detectionConfidence)
.toList());
break;
case AnnotationType.landmarkDetection:
case AnnotationType.logoDetection:
case AnnotationType.labelDetection:
case AnnotationType.textDetection:
case AnnotationType.objectLocalization:
scores.addAll(annotatedResponses.responses.first.annotations
.map((annotation) => annotation.score!)
.toList());
break;
default:
throw UsageException(
'${AnnotationType.values.byName(feature)} is not supported for this command.',
usage);
}
});
print(json.encode(scores));
} on DioException catch (err) {
throw UsageException('API usage error:', err.usage);
}
}