run method

  1. @override
void run()
override

Runs this command.

The return value is wrapped in a Future if necessary and returned by CommandRunner.runCommand.

Implementation

@override
void run() async {
  final googleVision = await GoogleVision.withJwtFile(
      globalResults!['credential-file'],
      'https://www.googleapis.com/auth/cloud-vision');

  final imageFile = File(argResults!['image-file']).readAsBytesSync();

  final aspectRatios = argResults?['aspect-ratios'] == null
      ? null
      : argResults!['aspect-ratios']
          .toString()
          .split(',')
          .map((aspectRatio) => double.parse(aspectRatio))
          .toList();

  final requests = AnnotationRequests(requests: [
    AnnotationRequest(
      jsonImage: JsonImage(byteBuffer: imageFile.buffer),
      features: [Feature(type: AnnotationType.cropHints)],
      imageContext: aspectRatios != null
          ? ImageContext(
              cropHintsParams: CropHintsParams(aspectRatios: aspectRatios),
            )
          : null,
    )
  ]);

  final annotatedResponses = await googleVision.annotate(requests: requests);

  print(annotatedResponses.responses);
}