从相机使用Firebase_ml_vision工具包时无法识别文本

时间:2019-07-01 18:11:20

标签: firebase flutter dart firebase-mlkit

我正在尝试构建一个使用Firebase_ml_vision软件包随附的文本识别的应用程序。当我使用Firebase.VisionImage.fromFile(pickedImage)并从互联网上下载带有文本的图片时,它的效果很好,但是当我尝试使用通过iPhone Xr相机拍摄的图像时,它并不能很好地读取文本。输出类似于以下内容:

颤动:2000 AADAT4A 颤动:2000 AADAT4A 扑动:20000 扑扑:03012 颤动:2000

当我尝试打印blocks.text行或元素时会发生这种情况。

有人对实现这一目标有想法吗?

我使用了以下代码:(不是所有代码,而是必需的)

File pickedImage;

List<String> words = [];

Future pickImage() async {
    var tempStore =
        await ImagePicker.pickImage(source: ImageSource.gallery); //gallery here
    setState(() {
      pickedImage = tempStore;
      isImageLoaded = true;
    });
  }

    Future pickCameraImage() async {
        var tempStore =
            await ImagePicker.pickImage(source: ImageSource.camera); //camera here
        setState(() {
          pickedImage = tempStore;
          isImageLoaded = true;
        });
      }

    Future readText() async {
        FirebaseVisionImage ourImage = FirebaseVisionImage.fromFile(pickedImage);
        TextRecognizer recognizeText = FirebaseVision.instance.textRecognizer();
        VisionText readText = await recognizeText.processImage(ourImage);

    for (TextBlock block in readText.blocks) {
//      final Rect boundingBox = block.boundingBox;
//      final List<Offset> cornerPoints = block.cornerPoints;
//      final String text = block.text;
//      final List<RecognizedLanguage> languages = block.recognizedLanguages;

      for (TextLine line in block.lines) {
        print(block.text);
        for (TextElement word in line.elements) {
          words.add(word.text);
        }
      }
    } isTextLoaded = true;
  }

在用户界面部分:

(...)

RaisedButton(
            child: Text('Pick an Image'),
            onPressed: pickImage,
          ),
          SizedBox(
            height: 10.0,
          ),
          RaisedButton(
            child: Text('Pick a Camera Image'),
            onPressed: pickCameraImage,
          ),
          SizedBox(
            height: 10.0,
          ),
          RaisedButton(
            child: Text('Read Text'),
            onPressed: readText,
          ),

(...)

我没有任何错误。有更多经验的人可以帮助我吗?谢谢

0 个答案:

没有答案