【问题标题】:Firebase Ml Vision Doesnt Recognize Image taken by Image Picker PluginFirebase Ml Vision 无法识别 Image Picker Plugin 拍摄的图像
【发布时间】:2020-02-28 20:11:28
【问题描述】:

我正在使用 firebase_ml_vision 包进行文本识别。它在 Android 端工作,但是当我测试它时,使用 image_picker 插件拍摄的真实 IOS 设备无法识别文本。我尝试转换为图像 Unit8 并且同样的问题不读取图像。

我需要转换图像吗?

这是我的图像选择器功能

    Future<Null> getImage(ImageSource source) async {
    try {
      var image = await ImagePicker.pickImage(source: source);

      var uuid = new Uuid();

      // Step 3: Get directory where we can duplicate selected file.
      Directory directory = await getApplicationDocumentsDirectory();
      String path = directory.path;
      String pathVar = path + '/' + uuid.v1() + '.png';
      await image.copy(pathVar);
      if (image != null) {
        _getImageSize(image);
        _imageFromGallery = image;
        _isLoaded = true;

        notifyListeners();
      } else {
        Flushbar(
          message: "Lütfen Resim Seçiniz",
        );
      }
    } catch (e) {
      _isLoaded = false;
      print(e.toString());
      notifyListeners();
    }
  }

这是我的 ml_vision 识别文本功能。

Future readText(BuildContext context) async {
    FirebaseVisionImage ourImage = FirebaseVisionImage.fromFile(
        Provider.of<CameraProvider>(context).imageFromSource);
    TextRecognizer recognizeText = FirebaseVision.instance.textRecognizer();
    VisionText readText = await recognizeText.processImage(ourImage);
    List<TextLine> lines = List();
    List<TextElement> words = List();
    List<TextBlock> box = List();

    try {
      for (TextBlock block in readText.blocks) {
        if (block.text != null) {
          box.add(block);
        }
        _textBox = box;
        notifyListeners();

        for (TextLine line in block.lines) {
          if (line.text != null) {
            lines.add(line);
          }

          _textLines = lines;
          notifyListeners();

          for (TextElement word in line.elements) {
            if (word.text != null) {
              words.add(word);
            }

            _textWords = words;
            notifyListeners();
          }
        }
      }
    } catch (e) {
      print(e);
    }
  }

【问题讨论】:

    标签: firebase flutter ocr firebase-mlkit mlvision


    【解决方案1】:

    你是否包含了该行

    pod 'Firebase/MLVisionTextModel'
    

    ios/Podfile 中并在ios/ 中运行pod update?如果您不这样做,结果将返回空。

    【讨论】:

    • 你有没有想过这个问题?据我所知,文本要么被镜像,要么在 iOS 设备上捕获的图像被旋转。
    猜你喜欢
    • 2018-06-05
    • 1970-01-01
    • 2020-04-10
    • 1970-01-01
    • 2017-12-07
    • 2018-04-18
    • 2017-05-16
    • 1970-01-01
    • 2020-02-06
    相关资源
    最近更新 更多