首页 > 解决方案 > Flutter Android从相机流中旋转图像以进行ocr

问题描述

再会。我正在为像我这样的盲人开发现金阅读器。我从相机流中获取图像,并使用正则表达式从钞票中获取数字并使用 google_ml_kit 获得提名。但它只有在钞票处于上升位置时才有效。因此,我还检查了数字是否以“0”开头,然后我希望图像旋转 180 度,或者 uint8list 是否翻转。但这是我遇到如何做到这一点的地方。我搜索并找不到翻转 uint8list 的方法,看看如果我反转它是否会起作用。此外,我似乎没有找到从相机流中旋转图像的方法。即使在下面的代码中有一个图像旋转变量,但如果我将其设置为 180,则什么也不做。谁能指导我找到解决方案。下面是我认为与此相关的部分代码。

    Future _processCameraImage(CameraImage image) async {
      final WriteBuffer allBytes = WriteBuffer();
      for (Plane plane in image.planes) {
        allBytes.putUint8List(plane.bytes);
      }
      final bytes = allBytes.done().buffer.asUint8List();

      final Size imageSize =
          Size(image.width.toDouble(), image.height.toDouble());

      final camera = cameras[_cameraIndex];
      final imageRotation =
          InputImageRotationMethods.fromRawValue(camera.sensorOrientation) ??
              InputImageRotation.Rotation_0deg;

      final inputImageFormat =
          InputImageFormatMethods.fromRawValue(image.format.raw) ??
              InputImageFormat.NV21;

      final planeData = image.planes.map(
        (Plane plane) {
          return InputImagePlaneMetadata(
            bytesPerRow: plane.bytesPerRow,
            height: plane.height,
            width: plane.width,
          );
        },
      ).toList();

      final inputImageData = InputImageData(
        size: imageSize,
        imageRotation: imageRotation,
        inputImageFormat: inputImageFormat,
        planeData: planeData,
      );

      final inputImage =
          InputImage.fromBytes(bytes: bytes, inputImageData: inputImageData);

    

      widget.onImage(inputImage);
      List? speakText = [];
      speakText = widget.outputText;
      if (speakText!.isNotEmpty) {
        await _speak('${widget.outputText}');
      } else {
        _speak('');
      }
    }

标签: androidimageflutterrotation

解决方案


推荐阅读